package cn.piesat.scanning.business.ads.single;

import cn.hutool.core.date.DateUtil;
import cn.piesat.scanning.business.ads.vo.RuleVO;
import cn.piesat.scanning.business.common.algorithm.processAlgorithm.SingleTaskAbstract;
import cn.piesat.scanning.dto.*;
import cn.piesat.scanning.service.*;
import cn.piesat.scanning.utils.FileUtil;
import com.alibaba.fastjson.JSON;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.persistence.criteria.CriteriaBuilder;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @author xhl
 */
@Component
public class AdsSingleTask extends SingleTaskAbstract {
    private Logger log = LoggerFactory.getLogger(AdsSingleTask.class);

    @Value("${scanning.data.day}")
    private Integer nearDay;

    private final DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");

    private static final String NULL = "NULL";
    /**
     * 同一谱段不同通道的时间差
     */
    private static final int DIFF_TIME_MINUTE = 3;

    private static final Logger logger = LoggerFactory.getLogger(AdsSingleTask.class);

    @Autowired
    private HtScanningMetadataService htScanningMetadataService;
    @Autowired
    private DbDmsSchedulerTaskFileRecordService dbDmsSchedulerTaskFileRecordService;
    @Autowired
    private HtPathConfigurationService htPathConfigurationService;
    @Autowired
    private DbDmsScanningMetadataAuxInfoService dbDmsScanningMetadataAuxInfoService;
    @Autowired
    private DbDmsScanningValidationService dbDmsScanningValidationService;
    @Autowired
    private HtAlgorithmConfigurationService htAlgorithmConfigurationService;

    @Override
    public void parseRuleAndFindData(Map<String, Object> inputParams, Map<String, Object> ruleParams,
                                     Map<String, Integer> indexParams, HtScheduleJobDTO taskDTO) {
        //规则参数
        AlgorithmTaskRuleParam taskRuleParam = JSON.parseObject(JSON.toJSONString(ruleParams), AlgorithmTaskRuleParam.class);
        //路径参数
        AlgorithmTaskPathParam taskPathParam = JSON.parseObject(JSON.toJSONString(inputParams), AlgorithmTaskPathParam.class);
        //判断规则不为NULL但是输入路径为空的情况
        if (!rulePathExist(taskRuleParam, taskPathParam)) {
            return;
        }
        Boolean preProcess = false;
        //TODO 暂时只满足1043 所有的主文件都一样
        RuleVO primaryRuleVO = JSON.parseObject(taskRuleParam.getPrimaryFile(), RuleVO.class);
        //查找可执行的数据，默认查找配置文件中配置的时间文件，[状态为重做的文件]，记录表中不存在的主文件
        List<HtScanningMetadataDTO> execMetadataList = new ArrayList<>();
        HtAlgorithmConfigurationDTO algorithmDTO = htAlgorithmConfigurationService.findById(taskDTO.getAlgoId());
        //获取算法标识 SWAPDSTDET
        String adsType = algorithmDTO.getAlgorithmIdentify();
        if ("TCTBCLMVL".equals(adsType) || "TCTBWPSH".equals(adsType)) {
            execMetadataList.addAll(selectEcExecMainFileList(primaryRuleVO, preProcess, taskDTO));
        } else {
            execMetadataList.addAll(selectExecMainFileList(primaryRuleVO, preProcess, taskDTO));
            execMetadataList.addAll(findRedoMetadataList(taskDTO.getId()));
        }
        logger.info("集合数量:" + String.valueOf(execMetadataList.size()));
        assemble(taskRuleParam, taskPathParam, indexParams, execMetadataList, taskDTO);

    }

    @Override
    public void parseRuleAndFindData(Map<String, Object> inputParams, Map<String, Object> ruleParams, HtScheduleJobDTO taskDTO) {

    }


    private void assemble(AlgorithmTaskRuleParam taskRuleParam, AlgorithmTaskPathParam taskPathParam, Map<String, Integer> indexParams,
                          List<HtScanningMetadataDTO> execMetadataList, HtScheduleJobDTO taskDTO) {
        //获取数据路径
        HtPathConfigurationDTO pathDTO = htPathConfigurationService.findById(taskDTO.getPathConfigId());
        Boolean preProcess = false;
        //获取算法信息 （算法名称，算法标识等）
        HtAlgorithmConfigurationDTO algorithmDTO = htAlgorithmConfigurationService.findById(taskDTO.getAlgoId());
        //获取算法标识 SWAPDSTDET
        String adsType = algorithmDTO.getAlgorithmIdentify();
        for (HtScanningMetadataDTO metadataDTO : execMetadataList) {
            Map<String, Object> execParams = new HashMap<>();
            //匹配primaryFile规则
            String primaryFile = pathDTO.getScanningPath() + File.separator + metadataDTO.getFilePath();
            execParams.put("preprocess", preProcess);
            execParams.put("algorithmId", taskDTO.getAlgoId());
            execParams.put("pathConfigId", taskDTO.getPathConfigId());
            execParams.put("fileDate", metadataDTO.getFileDate());
            execParams.put("lon", metadataDTO.getLon());
            execParams.put("lat", metadataDTO.getLat());
            execParams.put("taskPlanId", metadataDTO.getTaskPlanId());
            execParams.put("subPlanId", metadataDTO.getSubPlanId());
            execParams.put("viewNumber", metadataDTO.getViewNumber());
            execParams.put("productDir", pathDTO.getOutputPath());
            execParams.put("productType", taskPathParam.getProductType());
            //组装算法参数
            Map<String, Object> algorithmParams = new HashMap<>();
            try {
                algorithmParams = initAlgorithmParams(adsType, primaryFile, metadataDTO.getViewMode(), taskRuleParam, taskPathParam, indexParams);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            if ((algorithmParams.get("parameter01") == null && adsType.equals("SWAPLIGHT"))
                    || (algorithmParams.get("parameter01") == null && adsType.equals("ADSCLMVL"))
                    || (algorithmParams.get("parameter01") == null && adsType.equals("TCTBMDR"))
                    || (algorithmParams.get("parameter01") == null && adsType.equals("TCTGLCSA"))
                    || (algorithmParams.get("parameter01") == null && adsType.equals("TCTBWPSH"))
                    || (algorithmParams.get("parameter01") == null && adsType.equals("TCTBGIIRSGRID"))
                    || (algorithmParams.get("parameter01") == null && adsType.equals("TCTBCLMVL"))
                    || (algorithmParams.get("parameter01") == null && adsType.equals("TCTBGIIRS"))
                    || (algorithmParams.get("parameter01") == null && Objects.equals(adsType, "FYDQSST"))
                    || (algorithmParams.get("parameter01") == null && adsType.equals("SCBNOM"))
                    || (algorithmParams.get("parameter01") == null && adsType.equals("SWAPDRTVSWI"))

            ) {
                log.info("数据不存在,已经跳过");
                continue;
            } else {
                log.info("数据存在");
                updateRecordAndSendMessage(execParams, taskDTO, metadataDTO.getFileName(), metadataDTO.getFileDate(), algorithmParams);
            }
        }
    }

    private Map<String, Object> initAlgorithmParams(String adsType, String primaryFile, String ViewMode, AlgorithmTaskRuleParam taskRuleParam,
                                                    AlgorithmTaskPathParam taskPathParam, Map<String, Integer> indexParams) throws ParseException {
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMdd");
        primaryFile = FilenameUtils.separatorsToUnix(primaryFile);
        Map<String, Object> algorithmParams = new HashMap<>();
        algorithmParams.put("parameter00", primaryFile);
        algorithmParams.put("parameter01", checkVal(taskPathParam.getParameter01()));
        algorithmParams.put("parameter02", checkVal(taskPathParam.getParameter02()));
        algorithmParams.put("parameter03", checkVal(taskPathParam.getParameter03()));
        algorithmParams.put("parameter04", checkVal(taskPathParam.getParameter04()));
        algorithmParams.put("parameter05", checkVal(taskPathParam.getParameter05()));
        algorithmParams.put("parameter06", checkVal(taskPathParam.getParameter06()));
        algorithmParams.put("parameter07", checkVal(taskPathParam.getParameter07()));
        algorithmParams.put("parameter08", checkVal(taskPathParam.getParameter08()));
        algorithmParams.put("parameter09", checkVal(taskPathParam.getParameter09()));
        if ("ADSDETTIF".equals(adsType)) {
            //	"primaryFile": "/FY4A-_AGRI--_N_DISK_1047E_L3_DSTDET_MULT_NOM_20210314130000_20210314131459_4000M_HHMM_ADS_V0001.NC",
            //	"SourceType": "NC",
            //	"DataType": "int32",
            //	"DataSetName": "Dust",
            //	"GeotransformStr": "24.11662309,0.04,0,80.56672132,0,-0.04",
            //	"ProjectionStr": "等经纬度投影"
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("SourceType", checkVal(taskPathParam.getParameter01()));
            params.put("DataType", checkVal(taskPathParam.getParameter02()));
            params.put("DataSetName", checkVal(taskPathParam.getParameter03()));
            params.put("GeotransformStr", checkVal(taskPathParam.getParameter04()));
            params.put("ProjectionStr", checkVal(taskPathParam.getParameter05()));

            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
            algorithmParams.put("parameter02", null);
            algorithmParams.put("parameter03", null);
            algorithmParams.put("parameter04", null);
            algorithmParams.put("parameter05", null);

        } else if ("ADSDSTMAX".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            //	"primaryFile": ["FY4A-_AGRI--_N_DISK_1047E_L3_DSTDET_MULT_NOM_20210314130000_20210314131459_4000M_HHMM_ADS_V0001.tif",
            //                    "FY4A-_AGRI--_N_DISK_1047E_L3_DSTDET_MULT_NOM_20210314200000_20210314201459_4000M_HHMM_ADS_V0001.tif"],
            //	"ComposeType": "MAX",
            //	"InValidValue": [0],
            //	"timeAttribute": "POAD",
            //	"timeIndex": 0,
            //	"timeDefined": ["20211004000000","20211004235959"]
            //	"resultPath": "/home/BHW/WORK/graphics_process/results",
            //    "resultJsonFile": "/home/BHW/WORK/graphics_process/algo/outputJson/MaxCompose.json",
            //	"resultLogFile": "/home/BHW/WORK/graphics_process/algo/outputLog/MaxCompose.log",
            //
            //20210515000000
            //FY4A-_AGRI--_N_DISK_1047E_L3_DSTDET_MULT_NOM_20210314130000_20210314131459_4000M_HHMM_ADS_V0001.tif
            String[] fileName = primaryFile.split("_");
            //产品等级
            String level = fileName[5];
            //产品标识
            String productIid = fileName[6];
            //产品结束时间
            String endTime = fileName[9];
            String[] result = taskPathParam.getParameter05().split(",");
            String[] res = taskPathParam.getParameter04().split(",");
            int[] InValidValue = new int[res.length];
            int timeIndex = Integer.valueOf(taskPathParam.getParameter04());
            //产品类型
            String fileType = fileName[14].replace("V0001.", "");
            if (taskPathParam.getParameter03().equals("POAD")) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
                Date formatDate = sdf.parse(endTime);
                Calendar beginCal = Calendar.getInstance();
                beginCal.setTime(formatDate);
                beginCal.add(Calendar.HOUR_OF_DAY, -24);
                Date dateStart = beginCal.getTime();
                String minus1day = sdf.format(dateStart);
                String startTime = minus1day.substring(0, 8) + "000000";
                String timeAttribute = "HHMM";
                String[] filePath = htScanningMetadataService.listFileBySensorAndRangeTimeAndLevel(productIid, startTime, endTime, level, fileType, timeAttribute);
                for (int i = 0; i < filePath.length; i++) {
                    filePath[i] = "/mnt/swapdata/swapproduct/" + filePath[i];
                }
                params.put("primaryFile", filePath);
                params.put("ComposeType", checkVal(taskPathParam.getParameter01()));
                params.put("InValidValue", InValidValue);
                params.put("timeAttribute", checkVal(taskPathParam.getParameter03()));
                params.put("timeIndex", timeIndex);
                params.put("timeDefined", result);
            }
            if (taskPathParam.getParameter03().equals("POFD") && taskPathParam.getParameter04().equals("1")) {
                String timeAttribute = "POAD";
                String startTime = endTime.substring(0, 6) + "01000000";
                String[] filePath = htScanningMetadataService.listFileBySensorAndRangeTimeAndLevel(productIid, startTime, endTime, level, fileType, timeAttribute);
                for (int i = 0; i < filePath.length; i++) {
                    filePath[i] = "/mnt/swapdata/swapproduct/" + filePath[i];
                }
                params.put("primaryFile", filePath);
                params.put("ComposeType", checkVal(taskPathParam.getParameter01()));
                params.put("InValidValue", InValidValue);
                params.put("timeAttribute", checkVal(taskPathParam.getParameter03()));
                params.put("timeIndex", timeIndex);
                params.put("timeDefined", result);
            }
            if (taskPathParam.getParameter03().equals("POFD") && taskPathParam.getParameter04().equals("2")) {
                String timeAttribute = "POAD";
                String startTime = endTime.substring(0, 6) + "06000000";
                String[] filePath = htScanningMetadataService.listFileBySensorAndRangeTimeAndLevel(productIid, startTime, endTime, level, fileType, timeAttribute);
                for (int i = 0; i < filePath.length; i++) {
                    filePath[i] = "/mnt/swapdata/swapproduct/" + filePath[i];
                }
                params.put("primaryFile", filePath);
                params.put("ComposeType", checkVal(taskPathParam.getParameter01()));
                params.put("InValidValue", InValidValue);
                params.put("timeAttribute", checkVal(taskPathParam.getParameter03()));
                params.put("timeIndex", timeIndex);
                params.put("timeDefined", result);
            }
            if (taskPathParam.getParameter03().equals("POFD") && taskPathParam.getParameter04().equals("3")) {
                String timeAttribute = "POAD";
                String startTime = endTime.substring(0, 6) + "11000000";
                String[] filePath = htScanningMetadataService.listFileBySensorAndRangeTimeAndLevel(productIid, startTime, endTime, level, fileType, timeAttribute);
                for (int i = 0; i < filePath.length; i++) {
                    filePath[i] = "/mnt/swapdata/swapproduct/" + filePath[i];
                }
                params.put("primaryFile", filePath);
                params.put("ComposeType", checkVal(taskPathParam.getParameter01()));
                params.put("InValidValue", InValidValue);
                params.put("timeAttribute", checkVal(taskPathParam.getParameter03()));
                params.put("timeIndex", timeIndex);
                params.put("timeDefined", result);
            }
            if (taskPathParam.getParameter03().equals("POFD") && taskPathParam.getParameter04().equals("4")) {
                String timeAttribute = "POAD";
                String startTime = endTime.substring(0, 6) + "16000000";
                String[] filePath = htScanningMetadataService.listFileBySensorAndRangeTimeAndLevel(productIid, startTime, endTime, level, fileType, timeAttribute);
                for (int i = 0; i < filePath.length; i++) {
                    filePath[i] = "/mnt/swapdata/swapproduct/" + filePath[i];
                }
                params.put("primaryFile", filePath);
                params.put("ComposeType", checkVal(taskPathParam.getParameter01()));
                params.put("InValidValue", InValidValue);
                params.put("timeAttribute", checkVal(taskPathParam.getParameter03()));
                params.put("timeIndex", timeIndex);
                params.put("timeDefined", result);
            }
            if (taskPathParam.getParameter03().equals("POFD") && taskPathParam.getParameter04().equals("5")) {
                String timeAttribute = "POAD";
                String startTime = endTime.substring(0, 6) + "21000000";
                String[] filePath = htScanningMetadataService.listFileBySensorAndRangeTimeAndLevel(productIid, startTime, endTime, level, fileType, timeAttribute);
                for (int i = 0; i < filePath.length; i++) {
                    filePath[i] = "/mnt/swapdata/swapproduct/" + filePath[i];
                }
                params.put("primaryFile", filePath);
                params.put("ComposeType", checkVal(taskPathParam.getParameter01()));
                params.put("InValidValue", InValidValue);
                params.put("timeAttribute", checkVal(taskPathParam.getParameter03()));
                params.put("timeIndex", timeIndex);
                params.put("timeDefined", result);
            }
            if (taskPathParam.getParameter03().equals("POFD") && taskPathParam.getParameter04().equals("6")) {
                String timeAttribute = "POAD";
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
                Date formatDate = sdf.parse(endTime);
                Calendar beginCal = Calendar.getInstance();
                beginCal.setTime(formatDate);
                beginCal.add(Calendar.MONTH, -1);
                Date dateStart = beginCal.getTime();
                String minus1month = sdf.format(dateStart);
                String startTime = minus1month.substring(0, 6) + "26000000";
                String[] filePath = htScanningMetadataService.listFileBySensorAndRangeTimeAndLevel(productIid, startTime, endTime, level, fileType, timeAttribute);
                for (int i = 0; i < filePath.length; i++) {
                    filePath[i] = "/mnt/swapdata/swapproduct/" + filePath[i];
                }
                params.put("primaryFile", filePath);
                params.put("ComposeType", checkVal(taskPathParam.getParameter01()));
                params.put("InValidValue", InValidValue);
                params.put("timeAttribute", checkVal(taskPathParam.getParameter03()));
                params.put("timeIndex", timeIndex);
                params.put("timeDefined", result);
            }
            if (taskPathParam.getParameter03().equals("POTD") && taskPathParam.getParameter04().equals("1")) {
                String timeAttribute = "POAD";
                String startTime = endTime.substring(0, 6) + "01000000";
                String[] filePath = htScanningMetadataService.listFileBySensorAndRangeTimeAndLevel(productIid, startTime, endTime, level, fileType, timeAttribute);
                for (int i = 0; i < filePath.length; i++) {
                    filePath[i] = "/mnt/swapdata/swapproduct/" + filePath[i];
                }
                params.put("primaryFile", filePath);
                params.put("ComposeType", checkVal(taskPathParam.getParameter01()));
                params.put("InValidValue", InValidValue);
                params.put("timeAttribute", checkVal(taskPathParam.getParameter03()));
                params.put("timeIndex", timeIndex);
                params.put("timeDefined", result);
            }
            if (taskPathParam.getParameter03().equals("POTD") && taskPathParam.getParameter04().equals("2")) {
                String timeAttribute = "POAD";
                String startTime = endTime.substring(0, 6) + "11000000";
                String[] filePath = htScanningMetadataService.listFileBySensorAndRangeTimeAndLevel(productIid, startTime, endTime, level, fileType, timeAttribute);
                for (int i = 0; i < filePath.length; i++) {
                    filePath[i] = "/mnt/swapdata/swapproduct/" + filePath[i];
                }
                params.put("primaryFile", filePath);
                params.put("ComposeType", checkVal(taskPathParam.getParameter01()));
                params.put("InValidValue", InValidValue);
                params.put("timeAttribute", checkVal(taskPathParam.getParameter03()));
                params.put("timeIndex", timeIndex);
                params.put("timeDefined", result);
            }
            if (taskPathParam.getParameter03().equals("POTD") && taskPathParam.getParameter04().equals("3")) {
                String timeAttribute = "POAD";
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
                Date formatDate = sdf.parse(endTime);
                Calendar beginCal = Calendar.getInstance();
                beginCal.setTime(formatDate);
                beginCal.add(Calendar.MONTH, -1);
                Date dateStart = beginCal.getTime();
                String minus1month = sdf.format(dateStart);
                String startTime = minus1month.substring(0, 6) + "21000000";
                String[] filePath = htScanningMetadataService.listFileBySensorAndRangeTimeAndLevel(productIid, startTime, endTime, level, fileType, timeAttribute);
                for (int i = 0; i < filePath.length; i++) {
                    filePath[i] = "/mnt/swapdata/swapproduct/" + filePath[i];
                }
                params.put("primaryFile", filePath);
                params.put("ComposeType", checkVal(taskPathParam.getParameter01()));
                params.put("InValidValue", InValidValue);
                params.put("timeAttribute", checkVal(taskPathParam.getParameter03()));
                params.put("timeIndex", timeIndex);
                params.put("timeDefined", result);
            }
            if (taskPathParam.getParameter03().equals("POAM")) {
                String timeAttribute = "POAD";
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
                Date formatDate = sdf.parse(endTime);
                Calendar beginCal = Calendar.getInstance();
                beginCal.setTime(formatDate);
                beginCal.add(Calendar.MONTH, -1);
                Date dateStart = beginCal.getTime();
                String minus1month = sdf.format(dateStart);
                String startTime = minus1month.substring(0, 6) + "01000000";
                String[] filePath = htScanningMetadataService.listFileBySensorAndRangeTimeAndLevel(productIid, startTime, endTime, level, fileType, timeAttribute);
                for (int i = 0; i < filePath.length; i++) {
                    filePath[i] = "/mnt/swapdata/swapproduct/" + filePath[i];
                }
                params.put("primaryFile", filePath);
                params.put("ComposeType", checkVal(taskPathParam.getParameter01()));
                params.put("InValidValue", InValidValue);
                params.put("timeAttribute", checkVal(taskPathParam.getParameter03()));
                params.put("timeIndex", timeIndex);
                params.put("timeDefined", result);
            }
            if (taskPathParam.getParameter03().equals("POAS")) {
                String timeAttribute = "POAM";
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
                Date formatDate = sdf.parse(endTime);
                Calendar beginCal = Calendar.getInstance();
                beginCal.setTime(formatDate);
                beginCal.add(Calendar.MONTH, -3);
                Date dateStart = beginCal.getTime();
                String minus1month = sdf.format(dateStart);
                String startTime = minus1month.substring(0, 6) + "01000000";
                String[] filePath = htScanningMetadataService.listFileBySensorAndRangeTimeAndLevel(productIid, startTime, endTime, level, fileType, timeAttribute);
                for (int i = 0; i < filePath.length; i++) {
                    filePath[i] = "/mnt/swapdata/swapproduct/" + filePath[i];
                }
                params.put("primaryFile", filePath);
                params.put("ComposeType", checkVal(taskPathParam.getParameter01()));
                params.put("InValidValue", InValidValue);
                params.put("timeAttribute", checkVal(taskPathParam.getParameter03()));
                params.put("timeIndex", timeIndex);
                params.put("timeDefined", result);
            }
            if (taskPathParam.getParameter03().equals("POAY")) {
                String timeAttribute = "POAM";
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
                Date formatDate = sdf.parse(endTime);
                Calendar beginCal = Calendar.getInstance();
                beginCal.setTime(formatDate);
                beginCal.add(Calendar.YEAR, -1);
                Date dateStart = beginCal.getTime();
                String minus1month = sdf.format(dateStart);
                String startTime = minus1month.substring(0, 4) + "0101000000";
                String[] filePath = htScanningMetadataService.listFileBySensorAndRangeTimeAndLevel(productIid, startTime, endTime, level, fileType, timeAttribute);
                for (int i = 0; i < filePath.length; i++) {
                    filePath[i] = "/mnt/swapdata/swapproduct/" + filePath[i];
                }
                params.put("primaryFile", filePath);
                params.put("ComposeType", checkVal(taskPathParam.getParameter01()));
                params.put("InValidValue", InValidValue);
                params.put("timeAttribute", checkVal(taskPathParam.getParameter03()));
                params.put("timeIndex", timeIndex);
                params.put("timeDefined", result);
            }


            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
            algorithmParams.put("parameter02", null);
            algorithmParams.put("parameter03", null);
            algorithmParams.put("parameter04", null);
            algorithmParams.put("parameter05", null);

        } else if ("ADSDSTPNG".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            //FY4A-_AGRI--_N_DISK_1047E_L3_DSTTIF_MULT_NOM_20211207054500_20211207055959_4000M_HHMM_ADS_V0001.tif
            //FY4A-_AGRI--_N_DISK_1047E_L3_DSTDET_MULT_NOM_20210314130000_20210314131459_4000M_HHMM_ADS_V0001.tif
            //FY4A-_AGRI--_N_DISK_1047E_L3_DSTMAX_MULT_GLL_20211026000000_20211026235959_4000M_POAD_ADS_V0001.tif
            // 0      1    2   3    4    5    6     7   8      9               10          11   12
            String[] fileName = primaryFile.split("_");
            //日POAD、候POFD、旬POTD、月POAM、季POAS、年POAY
            String timeIndex = fileName[12];
            //日：  2021年10月26日
            //候 ：2021年10月第6候
            //旬   2021年10月下旬
            //月： 2021年10月
            //季： 2021年 秋季    12，1,2， 冬季
            //年：2021年：
            String date = null;
            if (timeIndex.equals("POAD")) {
                date = fileName[9].substring(0, 4) + "年" + fileName[9].substring(4, 6) + "月" + fileName[9].substring(6, 8) + "日";
            }
            if (timeIndex.equals("POFD")) {
                String code = fileName[9].substring(6, 8);
                switch (code) {
                    case "01":
                        date = fileName[9].substring(0, 4) + "年" + fileName[9].substring(4, 6) + "月第1候";
                        break;
                    case "06":
                        date = fileName[9].substring(0, 4) + "年" + fileName[9].substring(4, 6) + "月第2候";
                        break;
                    case "11":
                        date = fileName[9].substring(0, 4) + "年" + fileName[9].substring(4, 6) + "月第3候";
                        break;
                    case "16":
                        date = fileName[9].substring(0, 4) + "年" + fileName[9].substring(4, 6) + "月第4候";
                        break;
                    case "21":
                        date = fileName[9].substring(0, 4) + "年" + fileName[9].substring(4, 6) + "月第5候";
                        break;
                    case "26":
                        date = fileName[9].substring(0, 4) + "年" + fileName[9].substring(4, 6) + "月第6候";
                        break;
                }
            }
            if (timeIndex.equals("POTD")) {
                String code = fileName[9].substring(6, 8);
                switch (code) {
                    case "01":
                        date = fileName[9].substring(0, 4) + "年" + fileName[9].substring(4, 6) + "月上旬";
                        break;
                    case "11":
                        date = fileName[9].substring(0, 4) + "年" + fileName[9].substring(4, 6) + "月中旬";
                        break;
                    case "21":
                        date = fileName[9].substring(0, 4) + "年" + fileName[9].substring(4, 6) + "月下旬";
                        break;
                }
            }
            if (timeIndex.equals("POAM")) {
                date = fileName[9].substring(0, 4) + "年" + fileName[9].substring(4, 6) + "月";
            }
            if (timeIndex.equals("POAS")) {
                String code = fileName[9].substring(4, 6);
                switch (code) {
                    case "03":
                        date = fileName[9].substring(0, 4) + "年" + "春季";
                        break;
                    case "06":
                        date = fileName[9].substring(0, 4) + "年" + "夏季";
                        break;
                    case "09":
                        date = fileName[9].substring(0, 4) + "年" + "秋季";
                        break;
                    case "12":
                        date = fileName[9].substring(0, 4) + "年" + "冬季";
                        break;
                }
            }
            if (timeIndex.equals("POAY")) {
                date = fileName[9].substring(0, 4) + "年";
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            Date date1 = null;
            if (timeIndex.equals("HHMM")) {
                date1 = sdf.parse(fileName[9].substring(0, 12));
                Calendar cal = Calendar.getInstance();
                cal.setTime(date1);
                cal.add(Calendar.HOUR_OF_DAY, 8);
                date1 = cal.getTime();
                date = formatter.format(date1) + " (北京时间)";
            }

            params.put("inputfile", primaryFile);
            params.put("title", checkVal(taskPathParam.getParameter01()));
            params.put("date", date);
            params.put("qgstemplate", checkVal(taskPathParam.getParameter02()));

            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
            algorithmParams.put("parameter02", null);
        }
        //SWAPQPEPROVINCE QPE逐时降水按土地类型统计
        //SWAPQPELANDCOVER 逐时降水_按土地类型统计
        //SWAPLSTLANDCOVER 地表温度_按土地类型统计
        //SWAPLSTPROVINCE LST地表温度按土地类型统计
        else if ("SWAPQPEPROVINCE".equals(adsType) ||
                "SWAPQPELANDCOVER".equals(adsType) ||
                "SWAPLSTLANDCOVER".equals(adsType) ||
                "SWAPLSTPROVINCE".equals(adsType)) {
            algorithmParams.put("parameter00", checkVal(taskPathParam.getParameter01()));
            algorithmParams.put("parameter01", primaryFile);

        }//			SWAPNDVINOM=NDVI日产品
        //			SWAPDRTLST=地表温度日产品(干旱)
        //			SWAPATI=ATI日产品(表观热惯量)
        else if ("SWAPNDVINOM".equals(adsType) ||
                "SWAPATI".equals(adsType) ||
                "SWAPDRTLST".equals(adsType)
        ) {
            String[] fileName = primaryFile.split("_");

            primaryFile = fileName[9].substring(0, 8) + "000000";
            algorithmParams.put("parameter00", primaryFile);

        } else if ("SWAPHLAS".equals(adsType)) {
            String[] fileName = primaryFile.split("_");
            primaryFile = fileName[9];
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
            Date formatDate = sdf.parse(primaryFile);
            Calendar cal = Calendar.getInstance();
            cal.setTime(formatDate);
            cal.add(Calendar.HOUR_OF_DAY, -24);
            algorithmParams.put("parameter00", sdf.format(cal.getTime()));
        }
        //SWAPDRTCDI=干旱综合分析算法
        else if ("SWAPDRTCDI".equals(adsType)) {
            File file = new File(primaryFile);
            String tvdi = primaryFile.replace("ATI---", "TVDI--");
            File tvdi_file = new File(tvdi);
            String vswi = primaryFile.replace("ATI---", "VSWI--");
            File vswi_file = new File(vswi);
            if (tvdi_file.exists() && vswi_file.exists()) {

                //根据文件名 获取时间
                Pattern p = Pattern.compile(".*_(\\d{14})_\\d{14}_.*.NC$");
                Matcher m = p.matcher(file.getName());
                String time = "";
                if (m.find()) {
                    time = m.group(1);
                }
                if (!"".equals(time)) {
                    SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                    SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmm");
                    SimpleDateFormat df3 = new SimpleDateFormat("yyyyMMddHH");
                    SimpleDateFormat df4 = new SimpleDateFormat("yyyyMMdd");
                    Date timed = null;
                    try {
                        timed = df.parse(time);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    if (timed != null) {
                        String timeId = df.format(timed);
                        algorithmParams.put("parameter00", timeId);
                    }
                }

            }
        }//SWAPDRTVSWI=干旱_植被供水指数
        //SWAPDRTTVDI=干旱_温度植被指数
        //SWAPDRTTCI=干旱_温度条件指数
        //SWAPDRTVCI=干旱_植被条件指数
        else if ("SWAPDRTTVDI".equals(adsType) ||
                "SWAPDRTTCI".equals(adsType) ||
                "SWAPDRTVCI".equals(adsType)
        ) {
            //根据文件名 获取时间
            File file = new File(primaryFile);
            Pattern p = Pattern.compile(".*_(\\d{14})_\\d{14}_.*.NC$");
            Matcher m = p.matcher(file.getName());
            String time = "";
            if (m.find()) {
                time = m.group(1);
            }
            if (!"".equals(time)) {
                SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmm");
                SimpleDateFormat df3 = new SimpleDateFormat("yyyyMMddHH");
                SimpleDateFormat df4 = new SimpleDateFormat("yyyyMMdd");
                Date timed = null;
                try {
                    timed = df.parse(time);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                if (timed != null) {
                    String timeId = df.format(timed);
                    algorithmParams.put("parameter00", timeId);
                }
            }
        }
        else if ("SWAPDRTVSWI".equals(adsType)){
            //根据文件名 获取时间
            File file = new File(primaryFile);
            Pattern p = Pattern.compile(".*_(\\d{14})_\\d{14}_.*.NC$");
            Matcher m = p.matcher(file.getName());
            String time = "";
            if (m.find()) {
                time = m.group(1);
            }
            if (!"".equals(time)) {
                SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmm");
                SimpleDateFormat df3 = new SimpleDateFormat("yyyyMMddHH");
                SimpleDateFormat df4 = new SimpleDateFormat("yyyyMMdd");
                Date timed = null;
                try {
                    timed = df.parse(time);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                if (timed != null) {
                    String timeId = df.format(timed);
                    String lstPath = taskPathParam.getParameter02()+File.separator+timeId.substring(0,4)+File.separator+timeId.substring(0,8)+File.separator+file.getName().replace("NDVI--","LST---").replace("1000M","4000M");
                    File f = new File(lstPath);
                    if (!f.exists()){
                        algorithmParams.put("parameter01", null);
                        return algorithmParams;
                    }
                    algorithmParams.put("parameter00", timeId);
                }
            }
        }
        //多日统计
        //夏季风绘图
        //日统计
        else if ("SWAPNSAT".equals(adsType) ||
                "SWAPSUMWIND".equals(adsType) ||
                "SWAPSAT".equals(adsType)) {
            String[] fileName = primaryFile.split("_");
            LocalDate localDate = LocalDate.parse(fileName[9].substring(0, 8), dtf).minusDays(1);
            primaryFile = localDate.format(dtf);
            algorithmParams.put("parameter00", primaryFile);
        }//日显热通量
        //日地表实际散射
        //日地表净辐射通量
        ////多日地表实际散射/相对散射
        else if ("SWAPPOADHLAS".equals(adsType) ||
                "SWAPPOADSET".equals(adsType) ||
                "SWAPPOADSNR".equals(adsType) ||
                "SWAPPOFDSET".equals(adsType) ||
                "SWAPPOFDSRET".equals(adsType)) {
            String[] fileName = primaryFile.split("_");
            LocalDate localDate = LocalDate.parse(fileName[9].substring(0, 8), dtf);
            primaryFile = localDate.format(dtf);
            algorithmParams.put("parameter00", primaryFile);
        } else if ("SWAPCIE".equals(adsType)) {
            //{parameter07=,
            // parameter08=,
            // parameter09=,
            // parameter00=/mnt/FY4DATA/AGRI/L1/FDI/DISK//2021/20210909/FY4A-_AGRI--_N_DISK_1047E_L1-_FDI-_MULT_NOM_20210909170000_20210909171459_4000M_V0001.HDF,
            // parameter01=,
            // parameter02=/mnt/FY4DATA/AGRI/L2/CLP/DISK/NOM//2021/20210909/FY4A-_AGRI--_N_DISK_1047E_L2-_CLP-_MULT_NOM_20210909170000_20210909171459_4000M_V0001.NC,
            // parameter03=/mnt/FY4DATA/AGRI/L2/CLT/DISK/NOM//2021/20210909/FY4A-_AGRI--_N_DISK_1047E_L2-_CLT-_MULT_NOM_20210909170000_20210909171459_4000M_V0001.NC,
            // parameter04=/mnt/FY4DATA/AGRI/L2/CTH/DISK/NOM//2021/20210909/FY4A-_AGRI--_N_DISK_1047E_L2-_CTH-_MULT_NOM_20210909170000_20210909171459_4000M_V0001.NC,
            // parameter05=,
            // parameter06=}
            //找到当前的主文件
            String fdi = primaryFile;
            //半小时以前的文件夹
            String fdi30 = checkVal(taskPathParam.getParameter01());
            String fdi31 = checkVal(taskPathParam.getParameter01());
            File ff = new File(fdi);
            //获取文件名称
            String fileName = FileUtil.getFileName(ff.getAbsolutePath());
            //根据文件名 获取时间
            Pattern p = Pattern.compile("(\\d{4})(\\d{1,2})(\\d{1,2})(\\d{1,2})(\\d{1,2})(\\d{1,2})");
            Matcher m = p.matcher(fileName);
            String time = "";
            while (m.find()) {
                time = m.group();
                break;
            }
            //如果有正常时间继续
            if (!"".equals(time)) {
                //时间格式为 20190304230000
                SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                //获取时间
                Date timed = null;
                try {
                    timed = df.parse(time);
                } catch (ParseException e) {
                    //不做处理，结束
                    e.printStackTrace();
                }

                if (timed != null) {
                    //获取半小时以前的时间
                    Calendar c = Calendar.getInstance();
                    c.setTime(timed);
                    c.add(Calendar.MINUTE, -180);
                    String downFileNamePattern = ".*FDI.*4000M_V0001.HDF$";
                    String startTime = df.format(c.getTime());
                    //得到一个list list数组中 String[0]= 时间 String[0]= 文件名
                    // /mnt/FY4DATA/AGRI/L1/FDI/DISK
                    List<String[]> filePaths = getFilesByTime(fdi30, startTime, time, downFileNamePattern);
                    List<String> filesTimes = new ArrayList<String>();

                    //根据数组内容拼接参数
                    //#===========输入连续2个时次文件的后一个时次FY4A-L1-FDI文件;区域:全圆盘(中国区都可以); 分辨率:4000M
                    String path = "";
                    String fileTime = "";
                    if (filePaths != null && filePaths.size() > 0) {
                        //时间戳放到新的集合中
                        for (String[] filePath : filePaths) {
                            filesTimes.add(filePath[0]);
                        }
                        //新的时间进行排序
                        Collections.sort(filesTimes, new Comparator<String>() {

                            @Override
                            public int compare(String lhs, String rhs) {
                                // TODO Auto-generated method stub
                                int i = lhs.compareTo(rhs);
                                if (i > 0) {
                                    return 1;
                                } else {
                                    return -1;
                                }
                            }

                        });
                        //选择时间最大的一个
                        fileTime = filesTimes.get(filesTimes.size() - 1);
                        for (String[] filePath : filePaths) {

                            if (fileTime.equals(filePath[0])) {
                                //时次
                                String dataTime = filePath[0];
                                //路径文件名
                                String fn = filePath[1];
                                //拼接处所需格式
                                path = path + fdi31 + "\\" + dataTime.substring(0, 4) + "\\" + dataTime.substring(0, 8) + "\\" + fn;
                            }

                        }
                    }

                    algorithmParams.put("parameter01", path.replace("\\", "/"));
                    log.info(path);
                }
                //获取到时间以后，开始计算时间区间

                //=本时次L2级CLP数据;区域:全圆盘(中国区都可以); 分辨率:4000M parameter02
                //本时次L2级CLT数据;区域:全圆盘(中国区都可以); 分辨率:4000M parameter03
                //本时次L2级CTH数据;区域:全圆盘(中国区都可以); 分辨率:4000M parameter04


                getclp(algorithmParams, "parameter02", time);
                getclp(algorithmParams, "parameter03", time);
                getclp(algorithmParams, "parameter04", time);
                //判断假如L2级数据不存在，直接返回
                String clp = (String) algorithmParams.get("parameter02");
                String clt = (String) algorithmParams.get("parameter03");
                String cth = (String) algorithmParams.get("parameter04");
                if (!clp.endsWith(".NC")) {
                    return algorithmParams;
                }
                if (!clt.endsWith(".NC")) {
                    return algorithmParams;
                }
                if (!cth.endsWith(".NC")) {
                    return algorithmParams;
                }
            }


        }
        //LST地表温度日合成统计
        else if ("SWAPLSTPOAD".equals(adsType)) {
            String[] fileName = primaryFile.split("_");
            LocalDate localDate = LocalDate.parse(fileName[9].substring(0, 8), dtf);
            primaryFile = localDate.format(dtf);
            algorithmParams.put("parameter00", checkVal(taskPathParam.getParameter01()));
            algorithmParams.put("parameter01", primaryFile);
        } else if ("SWAPSTALIMESTATE".equals(adsType)) {
            // STA_FUSION_LIME_OBSandSTATE
            // 20210815000500
            // 20210815001000
            // /mnt/fy4data/LMI/L2/LMIE/REGX/2021/20210815/FY4A-_LMI---_N_REGX_1047E_L2-_LMIE_SING_NUL_20210815000510_20210815001449_7800M_N01V1.NC
            // /mnt/swapdata/Light_ADTD/20210815/2021081500.json
            // 1
            // 1
            File file = new File(primaryFile);
            String startTime = "";
            String endTime = "";
            //根据文件名 获取时间
            Pattern p = Pattern.compile(".*_(\\d{14})_\\d{14}_7800M_N0(\\d{1})V1.NC");
            Matcher m = p.matcher(file.getName());
            String time = "";
            String minte = "";
            if (m.find()) {
                time = m.group(1);
                minte = m.group(2);
            }
            //如果有正常时间继续
            if (!"".equals(time)) {
                //时间格式为 20190304230000
                SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmm");
                SimpleDateFormat df3 = new SimpleDateFormat("yyyyMMddHH");
                SimpleDateFormat df4 = new SimpleDateFormat("yyyyMMdd");

                //获取时间
                Date timed = null;
                try {
                    timed = df.parse(time);
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    //不做处理，结束

                }
                if (timed != null) {
                    String land_json = checkVal(taskPathParam.getParameter02()) + "\\" + df4.format(timed) + "\\" + df3.format(timed) + ".json";
                    //增加五分钟
                    Calendar c = Calendar.getInstance();
                    c.setTime(timed);
                    if (minte.equals("6")) {
                        c.add(Calendar.MINUTE, 5);
                        startTime = df2.format(c.getTime()) + "00";
                    } else {
                        startTime = df2.format(timed) + "00";
                    }
                    c.add(Calendar.MINUTE, 5);
                    endTime = df2.format(c.getTime()) + "00";
                    algorithmParams.put("parameter00", checkVal(taskPathParam.getParameter01()));
                    algorithmParams.put("parameter01", startTime);
                    algorithmParams.put("parameter02", endTime);
                    algorithmParams.put("parameter03", primaryFile);
                    algorithmParams.put("parameter04", land_json.replace("\\", "/"));
                }
            }
        } else if ("SWAPSTALIMESL".equals(adsType)) {
            String fy4a_l1_m = "FY4A-_AGRI--_N_REGC_1047E_L1-_FDI-_MULT_NOM_&3000_&3417_4000M_V0001.HDF";
            String fy4a_l2_qpe_m = "FY4A-_AGRI--_N_DISK_1047E_L2-_QPE-_MULT_NOM_&0000_&1459_4000M_V0001.NC";
            String fy4a_l2_cix_m = "FY4A-_AGRI--_N_REGC_1047E_L2-_CIX-_MULT_NOM_&3000_&3417_4000M_V0001.NC";
            String fy4a_l3_dcc_m = "FY4A-_AGRI--_N_REGC_1047E_L3_DCC---_MULT_NOM_&3000_&3417_4000M_HHMM_ADS_V0001.NC";
            String fy4a_l3_mcs_m = "FY4A-_AGRI--_N_REGC_1047E_L3_MCS---_MULT_NOM_&3000_&3417_4000M_HHMM_ADS_V0001.NC";

            String lime_hdf = primaryFile;
            String type = checkVal(taskPathParam.getParameter01());
            String fy4a_l1_disk_path = checkVal(taskPathParam.getParameter01());
            String fy4a_l2_qpe_path = checkVal(taskPathParam.getParameter02());
            String fy4a_l2_cix_path = checkVal(taskPathParam.getParameter03());
            String fy4a_l3_dcc_path = checkVal(taskPathParam.getParameter04());
            String fy4a_l3_mcs_path = checkVal(taskPathParam.getParameter05());
            String startTime = "";
            String endTime = "";
            File file = new File(lime_hdf);
            String fileName = file.getName();
            //根据文件名 获取时间
            Pattern p = Pattern.compile(".*_(\\d{14})_\\d{14}_7800M_N01V1.NC");
            Matcher m = p.matcher(fileName);
            String time = "";
            if (m.find()) {
                time = m.group(1);
            }
            //如果有正常时间继续
            if (!"".equals(time)) {
                //时间格式为 20190304230000
                SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmm");
                SimpleDateFormat df3 = new SimpleDateFormat("yyyyMMddHH");
                SimpleDateFormat df4 = new SimpleDateFormat("yyyyMMdd");
                SimpleDateFormat df5 = new SimpleDateFormat("yyyy");

                //获取时间
                Date timed = null;
                try {
                    timed = df.parse(time);
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    //不做处理，结束
                    e.printStackTrace();
                }
                if (timed != null) {

                    //增加五分钟
                    Calendar c = Calendar.getInstance();
                    c.setTime(timed);
                    startTime = df3.format(timed) + "0000";
                    c.add(Calendar.HOUR_OF_DAY, 1);
                    endTime = df3.format(c.getTime()) + "0000";
                    String fy4a_l1_disk_ = fy4a_l1_disk_path + "\\" + df5.format(timed) + "\\" + df4.format(timed) + "\\" + fy4a_l1_m.replace("&", df3.format(timed));
                    String fy4a_l2_qpe_ = fy4a_l2_qpe_path + "\\" + df5.format(timed) + "\\" + df4.format(timed) + "\\" + fy4a_l2_qpe_m.replace("&", df3.format(timed));
                    String fy4a_l2_cix_ = fy4a_l2_cix_path + "\\" + df5.format(timed) + "\\" + df4.format(timed) + "\\" + fy4a_l2_cix_m.replace("&", df3.format(timed));
                    String fy4a_l3_dcc_ = fy4a_l3_dcc_path + "\\" + df5.format(timed) + "\\" + df4.format(timed) + "\\" + fy4a_l3_dcc_m.replace("&", df3.format(timed));
                    String fy4a_l3_mcs_ = fy4a_l3_mcs_path + "\\" + df5.format(timed) + "\\" + df4.format(timed) + "\\" + fy4a_l3_mcs_m.replace("&", df3.format(timed));
                    String fy4a_l1_disk_filePath = fy4a_l1_disk_.replace("$", "");
                    String fy4a_l2_qpe_filePath = fy4a_l2_qpe_.replace("$", "");
                    String fy4a_l2_cix_filePath = fy4a_l2_cix_.replace("$", "");
                    String fy4a_l3_dcc_filePath = fy4a_l3_dcc_.replace("#", "");
                    String fy4a_l3_mcs_filePath = fy4a_l3_mcs_.replace("#", "");

                    File fy4a_l1_disk_file = new File(fy4a_l1_disk_filePath);
                    File fy4a_l2_qpe_file = new File(fy4a_l2_qpe_filePath);
                    File fy4a_l2_cix_file = new File(fy4a_l2_cix_filePath);
                    File fy4a_l3_dcc_file = new File(fy4a_l3_dcc_filePath);
                    File fy4a_l3_mcs_file = new File(fy4a_l3_mcs_filePath);
                    if (fy4a_l1_disk_file.exists() &&
                            fy4a_l2_qpe_file.exists() &&
                            fy4a_l2_cix_file.exists() &&
                            fy4a_l3_dcc_file.exists() &&
                            fy4a_l3_mcs_file.exists()) {
                        algorithmParams.put("parameter00", type);
                        algorithmParams.put("parameter01", startTime);
                        algorithmParams.put("parameter02", endTime);
                        algorithmParams.put("parameter03", lime_hdf);
                        algorithmParams.put("parameter04", fy4a_l1_disk_);
                        algorithmParams.put("parameter05", fy4a_l2_qpe_ + "," + fy4a_l2_cix_);
                        algorithmParams.put("parameter06", fy4a_l3_dcc_ + "," + fy4a_l3_mcs_);
                    }
                }

            }


        } else if ("SWAPFOGCHAR".equals(adsType)) {
            File file = new File(primaryFile);
            String[] filenames = file.getName().split("_");
            String year = filenames[9].substring(0, 4);
            String mon = filenames[9].substring(0, 8);
            String fdi = checkVal(taskPathParam.getParameter01());
            fdi = fdi.replace("$", "") + "/" + year + "/" + mon;
            File f = new File(fdi);
            File[] fs = f.listFiles();
            String resolution = filenames[11];
            for (File ff : fs) {
                String fn = FileUtil.getFileName(ff.getAbsolutePath());
                if (fn.contains(filenames[9]) && fn.contains("FDI") && fn.contains(resolution)) {
                    log.info(fn);
                    String r = ((String) algorithmParams.get("parameter01")) + "\\" + year + "\\" + mon + "\\" + fn;
                    algorithmParams.put("parameter01", r.replace("\\", "/"));
                }
            }

        } else if ("SWAPCONEXT".equals(adsType)) {
            //找到当前的主文件
            String fdi = primaryFile;
            //半小时以前的文件夹
            String fdi30 = checkVal(taskPathParam.getParameter01());
            String fdi31 = checkVal(taskPathParam.getParameter01());
            File ff = new File(fdi);
            //获取文件名称
            String fileName = FileUtil.getFileName(ff.getAbsolutePath());
            //根据文件名 获取时间
            Pattern p = Pattern.compile("(\\d{4})(\\d{1,2})(\\d{1,2})(\\d{1,2})(\\d{1,2})(\\d{1,2})");
            Matcher m = p.matcher(fileName);
            String time = "";
            while (m.find()) {
                time = m.group();
                break;
            }
            //如果有正常时间继续
            if (!"".equals(time)) {
                //时间格式为 20190304230000
                SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                //获取时间
                Date timed = null;
                try {
                    timed = df.parse(time);
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    //不做处理，结束
                    e.printStackTrace();
                }

                if (timed != null) {
                    //获取半小时以前的时间
                    Calendar c = Calendar.getInstance();
                    c.setTime(timed);
                    c.add(Calendar.MINUTE, -60);

                    String startTime = df.format(c.getTime());
                    //得到一个list list数组中 String[0]= 时间 String[0]= 文件名
                    String downFileNamePattern = ".*FDI.*4000M_V0001.HDF$";
                    List<String[]> filePaths = getFilesByTime(fdi30, startTime, time, downFileNamePattern);
                    //根据数组内容拼接参数
                    //"/home/ads/ADS_CONEXT/data/Z_SATE_C_BAWX_20181028014440_P_FY4A-_AGRI--_N_REGC_1047E_L1-_FDI-_MULT_NOM_20181028013417_20181028013833_4000M_V0001.HDF|/home/ads/ADS_CONEXT/data/Z_SATE_C_BAWX_20181028014051_P_FY4A-_AGRI--_N_REGC_1047E_L1-_FDI-_MULT_NOM_20181028013000_20181028013416_4000M_V0001.HDF" \
                    //根据算法要求 相邻的数据用 | 符号连接
                    String path = "";
                    for (String[] filePath : filePaths) {
                        //时次
                        String dataTime = filePath[0];
                        //路径文件名
                        String fn = filePath[1];
                        //拼接处所需格式
                        path = path + fdi31 + "\\" + dataTime.substring(0, 4) + "\\" + dataTime.substring(0, 8) + "\\" + fn + "+";
                    }
                    if (path.length() > 0) {
                        path = path.substring(0, path.length() - 1);
                    }
                    //增加双引号
                    //path = "\"" + path + "\"";
                    algorithmParams.put("parameter01", path.replace("\\", "/"));
                    //log.info(path);
                }
                //获取到时间以后，开始计算时间区间

            }

        } else if ("SWAPVOLMON".equals(adsType)) {
            //寻找CLM文件

            //找到当前的主文件
            String fdi = primaryFile;
            //半小时以前的文件夹
            String fdi30 = checkVal(taskPathParam.getParameter01());
            String fdi31 = checkVal(taskPathParam.getParameter01());
            String cth31 = checkVal(taskPathParam.getParameter02());

            fdi = fdi.replace("$", "");
            fdi30 = fdi30.replace("$", "");
            //获取文件名称
            File ff = new File(fdi);
            String fileName = FileUtil.getFileName(ff.getAbsolutePath());
            //根据文件名 获取时间
            Pattern p = Pattern.compile("(\\d{4})(\\d{1,2})(\\d{1,2})(\\d{1,2})(\\d{1,2})(\\d{1,2})");
            Matcher m = p.matcher(fileName);
            String time = "";
            while (m.find()) {
                time = m.group();
                break;
            }

            if (!"".equals(time)) {
                //时间格式为 20190304230000
                SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                //获取时间
                Date timed = null;
                try {
                    timed = df.parse(time);
                } catch (ParseException e) {
                    //不做处理，结束
                    e.printStackTrace();
                }

                if (timed != null) {
                    String nc = fileName.replace(".HDF", ".NC");
                    nc = nc.replace("L1", "L2");
                    nc = nc.replace("FDI", "CLM");
                    String year = time.substring(0, 4);
                    String yearMon = time.substring(0, 8);
                    String path = "";
                    path = path + fdi31 + "\\" + year + "\\" + yearMon + "\\" + nc;

                    algorithmParams.put("parameter01", path.replace("\\", "/"));

                    String cth = fileName.replace(".HDF", ".NC");
                    cth = cth.replace("L1", "L2");
                    cth = cth.replace("FDI", "CTH");
                    String cthyear = time.substring(0, 4);
                    String cthyearMon = time.substring(0, 8);
                    String cthpath = "";
                    cthpath = cthpath + cth31 + "\\" + cthyear + "\\" + cthyearMon + "\\" + cth;

                    algorithmParams.put("parameter02", cthpath.replace("\\", "/"));
                }
            }
        } else if ("SWAPSTALIMESL".equals(adsType)) {
            //找到当前的主文件
            String fdi = primaryFile;
            //半小时以前的文件夹
            String fdi30 = checkVal(taskPathParam.getParameter01());
            String fdi31 = checkVal(taskPathParam.getParameter01());
            File ff = new File(fdi);
            //获取文件名称
            String downFileNamePattern = ".*FDI.*4000M_V0001.HDF$";
            String fileName = FileUtil.getFileName(ff.getAbsolutePath());
            //根据文件名 获取时间
            Pattern p = Pattern.compile("(\\d{4})(\\d{1,2})(\\d{1,2})(\\d{1,2})(\\d{1,2})(\\d{1,2})");
            Matcher m = p.matcher(fileName);
            String time = "";
            while (m.find()) {
                time = m.group();
                break;
            }
            //如果有正常时间继续
            if (!"".equals(time)) {
                //时间格式为 20190304230000
                SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                //获取时间
                Date timed = null;
                try {
                    timed = df.parse(time);
                } catch (ParseException e) {
                    //不做处理，结束
                    e.printStackTrace();
                }

                if (timed != null) {
                    //获取半小时以前的时间
                    Calendar c = Calendar.getInstance();
                    c.setTime(timed);
                    c.add(Calendar.MINUTE, -180);

                    String startTime = df.format(c.getTime());
                    //得到一个list list数组中 String[0]= 时间 String[0]= 文件名
                    List<String[]> filePaths = getFilesByTime(fdi30, startTime, time, downFileNamePattern);
                    List<String> filesTimes = new ArrayList<String>();

                    //根据数组内容拼接参数
                    //#===========输入连续2个时次文件的后一个时次FY4A-L1-FDI文件;区域:全圆盘(中国区都可以); 分辨率:4000M
                    String path = "";
                    String fileTime = "";
                    if (filePaths != null && filePaths.size() > 0) {
                        //时间戳放到新的集合中
                        for (String[] filePath : filePaths) {
                            filesTimes.add(filePath[0]);
                        }
                        //新的时间进行排序
                        Collections.sort(filesTimes, new Comparator<String>() {

                            @Override
                            public int compare(String lhs, String rhs) {
                                // TODO Auto-generated method stub
                                int i = lhs.compareTo(rhs);
                                if (i > 0) {
                                    return 1;
                                } else {
                                    return -1;
                                }
                            }

                        });
                        //选择时间最大的一个
                        fileTime = filesTimes.get(filesTimes.size() - 1);
                        for (String[] filePath : filePaths) {

                            if (fileTime.equals(filePath[0])) {
                                //时次
                                String dataTime = filePath[0];
                                //路径文件名
                                String fn = filePath[1];
                                //拼接处所需格式
                                path = path + fdi31 + "\\" + dataTime.substring(0, 4) + "\\" + dataTime.substring(0, 8) + "\\" + fn;
                            }

                        }
                    }

                    algorithmParams.put("parameter01", path.replace("\\", "/"));
                }
            }
        } else if ("SWAPVOLMON".equals(adsType)) {
            //找到当前的主文件
            String fdi = primaryFile;
            //半小时以前的文件夹
            String fdi30 = checkVal(taskPathParam.getParameter01());
            String fdi31 = checkVal(taskPathParam.getParameter01());
            String cth31 = checkVal(taskPathParam.getParameter02());
            //获取文件名称
            File ff = new File(fdi);
            String fileName = FileUtil.getFileName(ff.getAbsolutePath());
            //根据文件名 获取时间
            Pattern p = Pattern.compile("(\\d{4})(\\d{1,2})(\\d{1,2})(\\d{1,2})(\\d{1,2})(\\d{1,2})");
            Matcher m = p.matcher(fileName);
            String time = "";
            while (m.find()) {
                time = m.group();
                break;
            }

            if (!"".equals(time)) {
                //时间格式为 20190304230000
                SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                //获取时间
                Date timed = null;
                try {
                    timed = df.parse(time);
                } catch (ParseException e) {
                    //不做处理，结束
                    e.printStackTrace();
                }
                if (timed != null) {
                    String nc = fileName.replace(".HDF", ".NC");
                    nc = nc.replace("L1", "L2");
                    nc = nc.replace("FDI", "CLM");
                    String year = time.substring(0, 4);
                    String yearMon = time.substring(0, 8);
                    String path = "";
                    path = path + fdi31 + "\\" + year + "\\" + yearMon + "\\" + nc;
                    algorithmParams.put("parameter01", path.replace("\\", "/"));
                    String cth = fileName.replace(".HDF", ".NC");
                    cth = cth.replace("L1", "L2");
                    cth = cth.replace("FDI", "CTH");
                    String cthyear = time.substring(0, 4);
                    String cthyearMon = time.substring(0, 8);
                    String cthpath = "";
                    cthpath = cthpath + cth31 + "\\" + cthyear + "\\" + cthyearMon + "\\" + cth;
                    algorithmParams.put("parameter02", cthpath.replace("\\", "/"));

                }
            }
        }//算法标识还没有明确qpe_lnq
        else if ("ADSPRELNQ".equals(adsType)) {
            File file = new File(primaryFile);
            algorithmParams.put("parameter00", taskPathParam.getParameter01());
            algorithmParams.put("parameter01", taskPathParam.getParameter02());
            algorithmParams.put("parameter02", taskPathParam.getParameter03());
            algorithmParams.put("parameter03", taskPathParam.getParameter04());
            algorithmParams.put("parameter04", file.getName());

        } else if ("SWAPLIGHT".equals(adsType)) {
            //                                   2021/20210910/FY4A-_AGRI--_N_DISK_1047E_L1-_FDI-_MULT_NOM_20210910000000_20210910001459_4000M_V0001.HDF
            // /mnt/fy4data/AGRI/L2/CTH/DISK/NOM/2021/20210910/FY4A-_AGRI--_N_DISK_1047E_L2-_CTH-_MULT_NOM_20210910000000_20210910001459_4000M_V0001.NC
            // /mnt/fy4data/AGRI/L2/CTH/DISK/NOM/2021/20210914/FY4A-_AGRI--_N_DISK_1047E_L2-_CTH-_MULT_NOM_20210914000000_20210914001459_4000M_V0001.NC
            String[] fileName = primaryFile.split("_");
            //主文件夹
            String year = fileName[9].substring(0, 4);
            String yearMon = fileName[9].substring(0, 8);
            File ff = new File(primaryFile);
            String CTHName = ff.getName().replace("L1", "L2").replace("FDI", "CTH").replace("HDF", "NC");
            String CTHPath = taskPathParam.getParameter01() + File.separator + year + File.separator + yearMon + File.separator + CTHName;
            log.info("CTH文件:" + CTHPath);
            File file = new File(CTHPath.replace("/mnt/fy4data/", "/mnt/FY4DATA/"));
            if (!file.exists()) {
                log.info("CTH文件不存在--1");
                algorithmParams.put("parameter01", null);
            } else {
                log.info("CTH文件存在---2");
                algorithmParams.put("parameter01", CTHPath);
            }
        } else if ("SWAPRDC".equals(adsType)) {
            //找到当前的主文件
            String fdi = primaryFile;
            //半小时以前的文件夹
            String fdi30 = checkVal(taskPathParam.getParameter01());
            String fdi31 = checkVal(taskPathParam.getParameter01());
            fdi = fdi.replace("$", "");
            fdi30 = fdi30.replace("$", "");
            File ff = new File(fdi);
            //获取文件名称
            String fileName = FileUtil.getFileName(ff.getAbsolutePath());
            //根据文件名 获取时间
            Pattern p = Pattern.compile("(\\d{4})(\\d{1,2})(\\d{1,2})(\\d{1,2})(\\d{1,2})(\\d{1,2})");
            Matcher m = p.matcher(fileName);
            String time = "";
            while (m.find()) {
                time = m.group();
                break;
            }
            //如果有正常时间继续
            if (!"".equals(time)) {
                //时间格式为 20190304230000
                SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                //获取时间
                Date timed = null;
                try {
                    timed = df.parse(time);
                } catch (ParseException e) {
                    //不做处理，结束
                    e.printStackTrace();
                }
                String downFileNamePattern = ".*FDI.*4000M_V0001.HDF$";
                if (timed != null) {
                    //获取半小时以前的时间
                    Calendar c = Calendar.getInstance();
                    c.setTime(timed);
                    c.add(Calendar.MINUTE, -180);

                    String startTime = df.format(c.getTime());
                    //得到一个list list数组中 String[0]= 时间 String[0]= 文件名
                    List<String[]> filePaths = getFilesByTime(fdi30, startTime, time, downFileNamePattern);
                    List<String> filesTimes = new ArrayList<String>();

                    //根据数组内容拼接参数
                    //#===========输入连续2个时次文件的后一个时次FY4A-L1-FDI文件;区域:全圆盘(中国区都可以); 分辨率:4000M
                    String path = "";
                    String fileTime = "";
                    if (filePaths != null && filePaths.size() > 0) {
                        //时间戳放到新的集合中
                        for (String[] filePath : filePaths) {
                            filesTimes.add(filePath[0]);
                        }
                        //新的时间进行排序
                        Collections.sort(filesTimes, new Comparator<String>() {

                            @Override
                            public int compare(String lhs, String rhs) {
                                // TODO Auto-generated method stub
                                int i = lhs.compareTo(rhs);
                                if (i > 0) {
                                    return 1;
                                } else {
                                    return -1;
                                }
                            }

                        });
                        //选择时间最大的一个
                        fileTime = filesTimes.get(filesTimes.size() - 1);
                        for (String[] filePath : filePaths) {

                            if (fileTime.equals(filePath[0])) {
                                //时次
                                String dataTime = filePath[0];
                                //路径文件名
                                String fn = filePath[1];
                                //拼接处所需格式
                                path = path + fdi31 + "\\" + dataTime.substring(0, 4) + "\\" + dataTime.substring(0, 8) + "\\" + fn;
                            }

                        }
                    }

                    algorithmParams.put("parameter01", path.replace("\\", "/"));
                    //log.info(path);
                }
                //获取到时间以后，开始计算时间区间

            }
        }
        // 模式订正
        else if ("ADSCLMVL".equals(adsType)) {
            DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyyMMddHH");
            String[] fileName = primaryFile.split("_");
            //主文件夹
            String year = fileName[9].substring(0, 4);
            String yearMon = fileName[9].substring(0, 8);
            String time = fileName[9].substring(8, 12);
            String yearAndmonAndDay = fileName[9].substring(0, 10);
            LocalDateTime localDate = LocalDateTime.parse(yearAndmonAndDay, dtf1);
            LocalDate localDate2 = LocalDate.parse(yearMon, dtf).minusDays(1);
            String Day = localDate.format(dtf1);
            String minus1Days = localDate2.format(dtf);
            String ECPath = "";
            String CLMPath = "";
            File file;
            File[] fs;
            Pattern p;
            if (time.equals("0000") || time.equals("0300") || time.equals("0600") || time.equals("0900") || time.equals("1200") || time.equals("1500") || time.equals("1800") || time.equals("2100")) {
                String ECPathAndName = "";
                String CLMpathAndName = "";
                log.info(time.substring(0, 2));
                if (Integer.valueOf(time.substring(0, 2)) >= 0 && Integer.valueOf(time.substring(0, 2)) < 12) {
                    ECPath = checkVal(taskPathParam.getParameter01()) + File.separator + minus1Days + File.separator + "12/tcc/";
                    CLMPath = checkVal(taskPathParam.getParameter02()) + File.separator + year + File.separator;
                    file = new File(ECPath);        //获取其file对象
                    fs = file.listFiles();
                    for (int i = 0; i < 4; i++) {
                        p = Pattern.compile("W_NAFP_C_ECMF_(\\d{14})_P_C1D(\\d{8})" + dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1).plusHours(-3 * i)).substring(4, 10) + "(\\d{2})1.tcc.nc");
                        if (file.exists()) {
                            for (File fi : fs) {
                                Matcher m = p.matcher(fi.getName());
                                while (m.find()) {
                                    File CLMFile = new File(CLMPath + dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1).plusHours(-3 * i)).substring(0, 8) + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L2-_CLM-_MULT_NOM_" + dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1).plusHours(-3 * i)) + "0000_" + dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1).plusHours(-3 * i)) + "1459_4000M_V0001.NC");
                                    if (CLMFile.exists()) {
                                        CLMpathAndName = CLMPath + dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1).plusHours(-3 * i)).substring(0, 8) + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L2-_CLM-_MULT_NOM_" + dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1).plusHours(-3 * i)) + "0000_" + dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1).plusHours(-3 * i)) + "1459_4000M_V0001.NC" + "," + CLMpathAndName;
                                    }
                                    ECPathAndName = ECPath + File.separator + m.group() + "," + ECPathAndName;
                                }
                            }
                        }
                    }
                    if (!ECPathAndName.contains(dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1)).substring(4, 10))) {
                        algorithmParams.put("parameter01", null);
                        return algorithmParams;
                    }
                } else {
                    CLMPath = checkVal(taskPathParam.getParameter02()) + File.separator + year + File.separator;
                    ECPath = checkVal(taskPathParam.getParameter01()) + File.separator + Day.substring(0, 8) + File.separator + "00/tcc/";
                    log.info(ECPath);
                    file = new File(ECPath);        //获取其file对象
                    fs = file.listFiles();
                    for (int i = 0; i < 4; i++) {
                        p = Pattern.compile("W_NAFP_C_ECMF_(\\d{14})_P_C1D(\\d{8})" + dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1).plusHours(-3 * i)).substring(4, 10) + "(\\d{2})1.tcc.nc");
                        if (file.exists()) {
                            for (File fi : fs) {
                                Matcher m = p.matcher(fi.getName());
                                while (m.find()) {
                                    File CLMFile = new File(CLMPath + dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1).plusHours(-3 * i)).substring(0, 8) + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L2-_CLM-_MULT_NOM_" + dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1).plusHours(-3 * i)) + "0000_" + dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1).plusHours(-3 * i)) + "1459_4000M_V0001.NC");
                                    if (CLMFile.exists()) {
                                        CLMpathAndName = CLMPath + dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1).plusHours(-3 * i)).substring(0, 8) + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L2-_CLM-_MULT_NOM_" + dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1).plusHours(-3 * i)) + "0000_" + dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1).plusHours(-3 * i)) + "1459_4000M_V0001.NC" + "," + CLMpathAndName;
                                    }
                                    ECPathAndName = ECPath + File.separator + m.group() + "," + ECPathAndName;
                                }
                            }
                        }
                    }
                    if (!ECPathAndName.contains(dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1)).substring(4, 10))) {
                        algorithmParams.put("parameter01", null);
                        return algorithmParams;
                    }
                }
                algorithmParams.put("parameter00", ECPathAndName.substring(0, ECPathAndName.length() - 1).replace("\\", "/"));
                algorithmParams.put("parameter01", CLMpathAndName.substring(0, CLMpathAndName.length() - 1).replace("\\", "/"));
                algorithmParams.put("parameter02", primaryFile);
            } else {
                algorithmParams.put("parameter01", null);
            }
        }
        // 模式订正
        else if ("TCTBCLMVL".equals(adsType)) {
            SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHH");
            SimpleDateFormat df1 = new SimpleDateFormat("MMddHH");
            String[] fileName = primaryFile.split("_");
            //  /mnt/fengyun_diqiu/tctbdata/Forecast/NAFP/ECMWF/HRES/20220519/00/gh/W_NAFP_C_ECMF_20220519054247_P_C1D05190000051900001.gh.nc
            //                                                                      0  1   2   3        4        5       6
            String ecFile = ViewMode;
            String[] ecFileName = ecFile.split("_");
            String EC_path = "";
            String clm_path = "";
            //12 09 06 03 00
            for (int i = 0; i < 4; i++) {
                Calendar cal = Calendar.getInstance();
                cal.setTime(df1.parse(ecFileName[6].substring(11, 17)));
                cal.add(Calendar.HOUR_OF_DAY, -i * 3);
                String ecfileDate = df1.format(cal.getTime());
                //                                  W_NAFP_C_ECMF_20220523175451_P_C1D05231200052403001.tcc.nc
                Pattern pattern = Pattern.compile("W_NAFP_C_ECMF_(\\d{14})_P_" + ecFileName[6].substring(0, 11) + ecfileDate + ecFileName[6].substring(17, 20) + ".gh.nc");
                File f = new File(ViewMode);
                String filePath = f.getAbsolutePath().replace("/mnt/fengyun_diqiu/tctbdata/", "/mnt/swapdata/").replace(f.getName(), "");
                File ec_File = new File(filePath);
                logger.info("文件路径:" + filePath);
                File[] fs = ec_File.listFiles();
                if (ec_File.exists()) {
                    for (File fi : fs) {
                        Matcher m = pattern.matcher(fi.getName());
                        while (m.find()) {
                            logger.info("ec_file:" + m.group());
                            EC_path = filePath + File.separator + m.group() + "," + EC_path;
                            Calendar calendar = Calendar.getInstance();
                            calendar.setTime(df.parse(fileName[9].substring(0, 10)));
                            calendar.add(Calendar.HOUR_OF_DAY, -i * 3);
                            String graFileDate = df.format(calendar.getTime());
                            String clm_file = "/mnt/FY4DATA/AGRI/L2/CLM/DISK/NOM/" + graFileDate.substring(0, 4) + File.separator + graFileDate.substring(0, 8) + File.separator
                                    + "FY4A-_AGRI--_N_DISK_1047E_L2-_CLM-_MULT_NOM_" + graFileDate + "0000_" + graFileDate.substring(0, 10) + "1459_4000M_V0001.NC";
                            clm_path = clm_file + "," + clm_path;
                        }
                    }
                }
            }
            if (EC_path.endsWith(",")) {
                EC_path = EC_path.substring(0, EC_path.length() - 1);
            }
            if (clm_path.endsWith(",")) {
                clm_path = clm_path.substring(0, clm_path.length() - 1);
            }
            algorithmParams.put("parameter00", EC_path.replace("gh", "tcc").replace("/mnt/swapdata/", "/mnt/fengyun_diqiu/tctbdata/"));
            algorithmParams.put("parameter01", clm_path.replace("\\", "/").replace("/mnt/FY4DATA/", "/mnt/FY4A/"));
            algorithmParams.put("parameter02", primaryFile);

        } else if ("TCTBGIIRS".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            String productID = taskPathParam.getProductType();
            //FY4A-_AGRI--_N_DISK_1047E_L1-_FDI-_MULT_NOM_20211231000000_20211231001459_4000M_V0001.HDF
            String[] fileName = primaryFile.split("_");
            String yearMon = fileName[9].substring(0, 8);
            String time = fileName[9].substring(0, 10);
            DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyyMMddHH");
            LocalDate localDate2 = LocalDate.parse(yearMon, dtf).minusDays(1);
            String minus1Days = localDate2.format(dtf);

            // /mnt/MAS89/giirs_data/GIIRS_2021123100grid2.dat
            params.put("primaryFile", primaryFile.replace("/mnt/FY4DATA", "/mnt/FY4A"));
            List<HtScanningMetadataDTO> h = htScanningMetadataService.findAllByFileName("GIIRS_" + time + "grid2.dat");
            if (h.isEmpty()) {
                algorithmParams.put("parameter01", null);
                return algorithmParams;
            }
            params.put("l2File", "/mnt/MAS89/giirs_data/GIIRS_" + time + "grid2.dat");
            params.put("lastFile", "/mnt/MAS89/giirs_data/GIIRS_" + minus1Days + time.substring(8, 10) + "grid2.dat");
            params.put("productID", productID);
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        }
        //TCTGLCSA
        /***
         * GIIRS温度
         * 地表温度
         * 对流初生
         * 海表温度
         * 云导风
         */
        else if ("TCTGLCSA".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            String productID = taskPathParam.getProductType();
            //FY4A-_AGRI--_N_DISK_1047E_L1-_FDI-_MULT_NOM_20211231000000_20211231001459_4000M_V0001.HDF
            String[] fileName = primaryFile.split("_");
            String year = fileName[9].substring(0, 4);
            String yearMon = fileName[9].substring(0, 8);
            String time = fileName[9].substring(0, 10);
            DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyyMMddHH");
            LocalDateTime localDate = LocalDateTime.parse(time, dtf1);
            LocalDate localDate2 = LocalDate.parse(yearMon, dtf).minusDays(1);
            String minus1Days = localDate2.format(dtf);
            File file;
            String ECPath = "";
            File[] fs;
            Pattern p;

            if ("GIIRS".equals(productID)) {
                // /mnt/MAS89/giirs_data/GIIRS_2021123100grid2.dat
                params.put("primaryFile", primaryFile.replace("/mnt/FY4DATA", "/mnt/FY4A"));
                List<HtScanningMetadataDTO> h = htScanningMetadataService.findAllByFileName("GIIRS_" + time + "grid2.dat");
                if (h.isEmpty()) {
                    algorithmParams.put("parameter01", null);
                    return algorithmParams;
                }
                params.put("l2File", "/mnt/MAS89/giirs_data/GIIRS_" + time + "grid2.dat");
                params.put("lastFile", "/mnt/MAS89/giirs_data/GIIRS_" + minus1Days + time.substring(8, 10) + "grid2.dat");
                params.put("productID", productID);
            } else if ("LST".equals(productID)) {
                ///mnt/FY4DATA/AGRI/L2/LST/DISK/NOM/2022/20220107/FY4A-_AGRI--_N_DISK_1047E_L2-_LST-_MULT_NOM_20220107000000_20220107001459_4000M_V0001.NC
                ///mnt/FY4DATA/AGRI/L2/AMV/DISK/C009/2022/20220107/FY4A-_AGRI--_N_DISK_1047E_L2-_AMV-_C009_NUL_20220107000000_20220107001459_064KM_V0001.NC
                params.put("primaryFile", primaryFile.replace("/mnt/FY4DATA", "/mnt/FY4A"));
                file = new File("/mnt/FY4DATA/AGRI/L2/LST/DISK/NOM/" + year + File.separator + yearMon + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L2-_LST-_MULT_NOM_" + time + "0000_" + time + "1459_4000M_V0001.NC");
                if (!file.exists()) {
                    algorithmParams.put("parameter01", null);
                    return algorithmParams;
                }
                params.put("l2File", "/mnt/FY4A/AGRI/L2/LST/DISK/NOM/" + year + File.separator + yearMon + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L2-_LST-_MULT_NOM_" + time + "0000_" + time + "1459_4000M_V0001.NC".replace("/mnt/FY4DATA", "/mnt/FY4A"));
                params.put("productID", productID);
            } else if ("CIX".equals(productID)) {
                ///mnt/FY4DATA/AGRI/L2/CIX/DISK/NOM/2022/20220107/FY4A-_AGRI--_N_DISK_1047E_L2-_CIX-_MULT_NOM_20220107000000_20220107001459_4000M_V0001.NC
                file = new File("/mnt/FY4DATA/AGRI/L2/CIX/DISK/NOM/" + year + File.separator + yearMon + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L2-_CIX-_MULT_NOM_" + time + "0000_" + time + "1459_4000M_V0001.NC");
                if (!file.exists()) {
                    algorithmParams.put("parameter01", null);
                    return algorithmParams;
                }
                params.put("primaryFile", primaryFile.replace("/mnt/FY4DATA", "/mnt/FY4A"));
                params.put("l2File", "/mnt/FY4A/AGRI/L2/CIX/DISK/NOM/" + year + File.separator + yearMon + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L2-_CIX-_MULT_NOM_" + time + "0000_" + time + "1459_4000M_V0001.NC".replace("/mnt/FY4DATA", "/mnt/FY4A"));
                params.put("productID", productID);
            } else if ("CIX2".equals(productID)) {
                ///mnt/FY4DATA/AGRI/L2/CIX/DISK/NOM/2022/20220107/FY4A-_AGRI--_N_DISK_1047E_L2-_CIX-_MULT_NOM_20220107000000_20220107001459_4000M_V0001.NC
                file = new File("/mnt/FY4DATA/AGRI/L2/CIX/" + fileName[3] + "/NOM/" + year + File.separator + yearMon + File.separator + "FY4A-_AGRI--_N_" + fileName[3] + "_1047E_L2-_CIX-_MULT_NOM_" + fileName[9] + "_" + fileName[10] + "_4000M_V0001.NC");
                if (!file.exists()) {
                    algorithmParams.put("parameter01", null);
                    return algorithmParams;
                }
                params.put("primaryFile", primaryFile.replace("/mnt/FY4DATA", "/mnt/FY4A"));
                params.put("l2File", "/mnt/FY4DATA/AGRI/L2/CIX/" + fileName[3] + "/NOM/" + year + File.separator + yearMon + File.separator + "FY4A-_AGRI--_N_" + fileName[3] + "_1047E_L2-_CIX-_MULT_NOM_" + fileName[9] + "_" + fileName[10] + "_4000M_V0001.NC".replace("/mnt/FY4DATA", "/mnt/FY4A"));
                params.put("productID", productID);
            } else if ("SST".equals(productID)) {
                ///mnt/FY4DATA/AGRI/L2/SST/DISK/NOM/2022/20220107/FY4A-_AGRI--_N_DISK_1047E_L2-_SST-_MULT_NOM_20220107000000_20220107001459_4000M_V0001.NC
                file = new File("/mnt/FY4DATA/AGRI/L2/SST/DISK/NOM/" + year + File.separator + yearMon + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L2-_SST-_MULT_NOM_" + time + "0000_" + time + "1459_4000M_V0001.NC");
                if (!file.exists()) {
                    algorithmParams.put("parameter01", null);
                    return algorithmParams;
                }
                params.put("primaryFile", primaryFile.replace("/mnt/FY4DATA", "/mnt/FY4A"));
                params.put("l2File", "/mnt/FY4A/AGRI/L2/SST/DISK/NOM/" + year + File.separator + yearMon + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L2-_SST-_MULT_NOM_" + time + "0000_" + time + "1459_4000M_V0001.NC".replace("/mnt/FY4DATA", "/mnt/FY4A"));
                params.put("productID", productID);
            } else if ("AMV".equals(productID)) {
                ///mnt/FY4DATA/AGRI/L2/AMV/DISK/C009/2022/20220107/FY4A-_AGRI--_N_DISK_1047E_L2-_AMV-_C009_NUL_20220107000000_20220107001459_064KM_V0001.NC
                String C009FileName = "/mnt/FY4DATA/AGRI/L2/AMV/DISK/C009/" + year + File.separator + yearMon + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L2-_AMV-_C009_NUL_" + time + "0000_" + time + "1459_064KM_V0001.NC";
                String C010FileName = "/mnt/FY4DATA/AGRI/L2/AMV/DISK/C010/" + year + File.separator + yearMon + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L2-_AMV-_C010_NUL_" + time + "0000_" + time + "1459_064KM_V0001.NC";
                String C012FileName = "/mnt/FY4DATA/AGRI/L2/AMV/DISK/C012/" + year + File.separator + yearMon + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L2-_AMV-_C012_NUL_" + time + "0000_" + time + "1459_064KM_V0001.NC";

                file = new File(C009FileName);
                if (!file.exists()) {
                    algorithmParams.put("parameter01", null);
                    return algorithmParams;
                }
                file = new File(C010FileName);
                if (!file.exists()) {
                    algorithmParams.put("parameter01", null);
                    return algorithmParams;
                }
                file = new File(C012FileName);
                if (!file.exists()) {
                    algorithmParams.put("parameter01", null);
                    return algorithmParams;
                }

                file = new File("/mnt/FY4DATA/AGRI/L2/AMV/DISK/C009/" + year + File.separator + yearMon + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L2-_AMV-_C009_NUL_" + time + "0000_" + time + "1459_064KM_V0001.NC");
                if (!file.exists()) {
                    algorithmParams.put("parameter01", null);
                    return algorithmParams;
                }
                String[] l2File = {C009FileName.replace("/mnt/FY4DATA", "/mnt/FY4A"), C010FileName.replace("/mnt/FY4DATA", "/mnt/FY4A"), C012FileName.replace("/mnt/FY4DATA", "/mnt/FY4A")};
                params.put("primaryFile", primaryFile.replace("/mnt/FY4DATA", "/mnt/FY4A"));
                params.put("l2File", l2File);
                params.put("productID", productID);
            } else if ("WWEC".equals(productID) || "WHQEC".equals(productID)) {

                String ecGhFile = "";
                if (Integer.valueOf(time.substring(0, 2)) >= 0 && Integer.valueOf(time.substring(0, 2)) < 12) {
                    ECPath = "/mnt/swapdata/Forecast/NAFP/ECMWF/HRES/" + File.separator + minus1Days + File.separator + "12/gh/";
                    file = new File(ECPath);        //获取其file对象
                    fs = file.listFiles();
                    p = Pattern.compile("W_NAFP_C_ECMF_(\\d{14})_P_C1D(\\d{8})" + dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1)).substring(4, 10) + "(\\d{2})1.gh.nc");
                    if (file.exists()) {
                        for (File fi : fs) {
                            Matcher m = p.matcher(fi.getName());
                            while (m.find()) {
                                ecGhFile = ECPath + File.separator + m.group();
                            }
                        }
                    }
                } else {
                    ECPath = "/mnt/swapdata/Forecast/NAFP/ECMWF/HRES/" + File.separator + time.substring(0, 8) + File.separator + "00/gh/";
                    file = new File(ECPath);        //获取其file对象
                    fs = file.listFiles();
                    p = Pattern.compile("W_NAFP_C_ECMF_(\\d{14})_P_C1D(\\d{8})" + dtf1.format(LocalDateTime.parse(dtf1.format(localDate), dtf1)).substring(4, 10) + "(\\d{2})1.gh.nc");
                    if (file.exists()) {
                        for (File fi : fs) {
                            Matcher m = p.matcher(fi.getName());
                            while (m.find()) {
                                ecGhFile = ECPath + File.separator + m.group();
                            }
                        }
                    }
                }
                log.info(ECPath);
                if ("".equals(ecGhFile)) {
                    algorithmParams.put("parameter01", null);
                    return algorithmParams;
                }
                params.put("primaryFile", primaryFile.replace("/mnt/FY4DATA", "/mnt/FY4A"));
                params.put("productID", productID);
                params.put("ecGhFile", ecGhFile.replace("\\", "/").replace("/mnt/swapdata/", "/mnt/fengyun_diqiu/tctbdata/"));
                params.put("ecUwindFile", ecGhFile.replace("\\", "/").replace("/mnt/swapdata/", "/mnt/fengyun_diqiu/tctbdata/").replace("gh", "u"));
                params.put("ecVwindFile", ecGhFile.replace("\\", "/").replace("/mnt/swapdata/", "/mnt/fengyun_diqiu/tctbdata/").replace("gh", "v"));
            }
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("TCTBMDR".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            String productID = taskPathParam.getProductType();
            File file;
            //FY4A-_AGRI--_N_DISK_1047E_L1-_FDI-_MULT_NOM_20211231000000_20211231001459_4000M_V0001.HDF
            String[] fileName = primaryFile.split("_");
            String year = fileName[9].substring(0, 4);
            String yearMon = fileName[9].substring(0, 8);
            String time = fileName[9].substring(0, 10);
            String MCSFileName = "/mnt/swapdata/swapproduct/FY4A/AGRI/L3/DISK/HHMM/MCS---/NOM/" + year + "/" + yearMon + "/FY4A-_AGRI--_N_DISK_1047E_L3_MCS---_MULT_NOM_" + time + "0000_" + time + "1459_4000M_HHMM_ADS_V0001.NC";
            String DCCFileName = "/mnt/swapdata/swapproduct/FY4A/AGRI/L3/DISK/HHMM/DCC---/NOM/" + year + "/" + yearMon + "/FY4A-_AGRI--_N_DISK_1047E_L3_DCC---_MULT_NOM_" + time + "0000_" + time + "1459_4000M_HHMM_ADS_V0001.NC";
            String RDCFileName = "/mnt/swapdata/swapproduct/FY4A/AGRI/L3/DISK/HHMM/RDC---/NOM/" + year + "/" + yearMon + "/FY4A-_AGRI--_N_REGC_1047E_L3_RDC---_MULT_NOM_" + time + "0000_" + time + "1459_4000M_HHMM_ADS_V0001.NC";
            ;
            file = new File(MCSFileName);
            if (!file.exists()) {
                algorithmParams.put("parameter01", null);
                return algorithmParams;
            }
            file = new File(DCCFileName);
            if (!file.exists()) {
                algorithmParams.put("parameter01", null);
                return algorithmParams;
            }
            file = new File(RDCFileName);
            if (!file.exists()) {
                algorithmParams.put("parameter01", null);
                return algorithmParams;
            }
            String[] adsFile = {MCSFileName, DCCFileName, RDCFileName};
            params.put("primaryFile", primaryFile);
            params.put("adsFile", adsFile);
            params.put("productID", productID);
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("TCTBMAP".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile.replace("/mnt/FY4DATA", "/mnt/FY4A"));
            params.put("productName", taskPathParam.getProductType());
            params.put("auxPath", taskPathParam.getParameter01());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("TCTBWPSH".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            String EC_path = ViewMode;
            params.put("primaryFile", primaryFile.replace("/mnt/FY4DATA", "/mnt/FY4A"));
            params.put("ModelFile", EC_path.replace("\\", "/").replace("/mnt/swapdata/", "/mnt/fengyun_diqiu/tctbdata/"));
            params.put("auxPath", "/home/WPSH_inArspy/StaticFile");
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("TCTBGIIRSGRID".equals(adsType)) {
            //GIIRS_2022010920grid2.dat
            //0       1
            Map<String, Object> params = new HashMap<>();
            DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyyMMddHH");
            String[] fileName = primaryFile.split("_");
            //主文件夹
            String yearMon = fileName[2].substring(0, 8);
            String time = fileName[2].substring(8, 10);
            int ec_hour = Integer.parseInt(time);
            int yu = ec_hour % 3;
            switch (yu) {
                case 0:
                    break;
                case 1:
                    ec_hour = ec_hour - 1;
                    break;
                case 2:
                    ec_hour = ec_hour + 1;
                    break;
            }

            String ec_hour_str = String.format("%02d", ec_hour);
            String yearMonDay = fileName[2].substring(0, 10);
            String ec_day = fileName[2].substring(0, 8);
            LocalDateTime ec_localDate = LocalDateTime.parse(ec_day + ec_hour_str, dtf1);


            LocalDateTime localDate = LocalDateTime.parse(yearMonDay, dtf1);
            LocalDate localDate2 = LocalDate.parse(yearMon, dtf).minusDays(1);
            String Day = localDate.format(dtf1);
            String minus1Days = localDate2.format(dtf);
            String ECPath = "";
            File file;
            File[] fs;
            Pattern p;
            String girdMinus1Days = "/mnt/MAS89/giirs_data/" + "GIIRS_" + minus1Days + time.substring(0, 2) + "grid2.dat";
            String ECPathAndName = "";
            log.info(taskPathParam.getParameter01());
            if (Integer.valueOf(time.substring(0, 2)) >= 0 && Integer.valueOf(time.substring(0, 2)) < 12) {
                ECPath = checkVal(taskPathParam.getParameter01()) + File.separator + minus1Days + File.separator + "12/q/";
                log.info(ECPath);
                file = new File(ECPath);        //获取其file对象
                fs = file.listFiles();
                p = Pattern.compile("W_NAFP_C_ECMF_(\\d{14})_P_C1D(\\d{8})" + dtf1.format(LocalDateTime.parse(dtf1.format(ec_localDate), dtf1)).substring(4, 10) + "(\\d{2})1.q.nc");
                if (file.exists()) {
                    for (File fi : fs) {
                        Matcher m = p.matcher(fi.getName());
                        while (m.find()) {
                            ECPathAndName = ECPath + File.separator + m.group();
                        }
                    }
                }
            } else {
                ECPath = checkVal(taskPathParam.getParameter01()) + File.separator + Day.substring(0, 8) + File.separator + "00/q/";
                log.info(ECPath);
                file = new File(ECPath);        //获取其file对象
                fs = file.listFiles();
                p = Pattern.compile("W_NAFP_C_ECMF_(\\d{14})_P_C1D(\\d{8})" + dtf1.format(LocalDateTime.parse(dtf1.format(ec_localDate), dtf1)).substring(4, 10) + "(\\d{2})1.q.nc");
                if (file.exists()) {
                    for (File fi : fs) {
                        Matcher m = p.matcher(fi.getName());
                        while (m.find()) {
                            ECPathAndName = ECPath + File.separator + m.group();
                        }
                    }
                }
            }
            switch (time) {
                case "00":
                case "06":
                case "12":
                    switch (ECPathAndName) {
                        case "":
                            algorithmParams.put("parameter01", null);
                            break;
                        default:
                            params.put("ecFile", ECPathAndName.replace("\\", "/").replace("/mnt/swapdata/", "/mnt/fengyun_diqiu/tctbdata/"));
                            break;
                    }
                    break;
                default:
                    switch (ECPathAndName) {
                        case "":
                            params.put("ecFile", " ");
                            break;
                        default:
                            params.put("ecFile", ECPathAndName.replace("\\", "/").replace("/mnt/swapdata/", "/mnt/fengyun_diqiu/tctbdata/"));
                            break;
                    }
                    break;
            }

            params.put("primaryFile", primaryFile);
            params.put("lastFile", girdMinus1Days);
            params.put("productID", taskPathParam.getProductType());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("TCTBSNF".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("cloudFile", primaryFile.replace("V0001.tif", "V0001_cloudMasked.tif"));
            params.put("auxPath", taskPathParam.getParameter01());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("TCTBSND".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("auxPath", taskPathParam.getParameter01());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("TCTBSCT".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("auxPath", taskPathParam.getParameter01());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        }
        //海表温度
        else if ("FYDQSST".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            String[] fileName = primaryFile.split("_");
            String year = fileName[9].substring(0, 4);
            String yearMon = fileName[9].substring(0, 8);
            String st_time = fileName[9].substring(0, 14);
            String en_time = fileName[10].substring(0, 14);
            File file;
            ///mnt/FY4A/AGRI/L1/FDI/DISK/2021/20211231/FY4A-_AGRI--_N_DISK_1047E_L1-_FDI-_MULT_NOM_20211231000000_20211231001459_4000M_V0001.HDF
            ///mnt/FY4A/AGRI/L2/SST/DISK/NOM/2022/20220324/FY4A-_AGRI--_N_DISK_1047E_L2-_SST-_MULT_NOM_20220324000000_20220324001459_4000M_V0001.NC
            ///fengyun_diqiu/data/FY4A/AGRI/truecolor/2022/20220321/FY4A-_AGRI--_N_DISK_1047E_L1-_FDI-_MULT_NOM_20220321181500_20220321182959_1000M_V0001.tif
            file = new File("/mnt/FY4A/AGRI/L2/SST/DISK/NOM/" + year + File.separator + yearMon + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L2-_SST-_MULT_NOM_" + st_time + "_" + en_time + "_4000M_V0001.NC");
            if (!file.exists()) {
                algorithmParams.put("parameter01", null);
                return algorithmParams;
            }
            file = new File("/fengyun_diqiu/data/FY4A/AGRI/truecolor/" + year + File.separator + yearMon + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L1-_FDI-_MULT_NOM_" + st_time + "_" + en_time + "_1000M_V0001.tif");
            if (!file.exists()) {
                algorithmParams.put("parameter01", null);
                return algorithmParams;
            }
            params.put("primaryFile", primaryFile);
            params.put("l2File", "/mnt/FY4A/AGRI/L2/SST/DISK/NOM/" + year + File.separator + yearMon + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L2-_SST-_MULT_NOM_" + st_time + "_" + en_time + "_4000M_V0001.NC");
            params.put("trueColorFile", "/fengyun_diqiu/data/FY4A/AGRI/truecolor/" + year + File.separator + yearMon + File.separator + "FY4A-_AGRI--_N_DISK_1047E_L1-_FDI-_MULT_NOM_" + st_time + "_" + en_time + "_1000M_V0001.tif");
            params.put("productID", taskPathParam.getParameter01());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        }
        //闪电频次
        else if ("FYDQLMIE".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("productID", taskPathParam.getParameter01());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        }
        //GIIRS温度
        else if ("FYDQT3D".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("lastFile", taskPathParam.getParameter01());
            params.put("productID", taskPathParam.getParameter01());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        }
        else if ("SWAPFSC".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("productID", taskPathParam.getParameter01());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        }
        //对流指数
        else if ("FYDQCVI".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("productID", taskPathParam.getParameter01());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("FYDQMDR".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            String productID = taskPathParam.getProductType();
            File file;
            //FY4A-_AGRI--_N_DISK_1047E_L1-_FDI-_MULT_NOM_20211231000000_20211231001459_4000M_V0001.HDF
            String[] fileName = primaryFile.split("_");
            String year = fileName[9].substring(0, 4);
            String yearMon = fileName[9].substring(0, 8);
            String time = fileName[9].substring(0, 10);
            String MCSFileName = "/mnt/fengyun_diqiu/tctbdata/tctbproduct/FY4A/AGRI/L3/DISK/HHMM/MCS---/NOM/" + year + "/" + yearMon + "/FY4A-_AGRI--_N_DISK_1047E_L3_MCS---_MULT_NOM_" + time + "0000_" + time + "1459_4000M_HHMM_ADS_V0001.NC";
            String DCCFileName = "/mnt/fengyun_diqiu/tctbdata/tctbproduct/FY4A/AGRI/L3/DISK/HHMM/DCC---/NOM/" + year + "/" + yearMon + "/FY4A-_AGRI--_N_DISK_1047E_L3_DCC---_MULT_NOM_" + time + "0000_" + time + "1459_4000M_HHMM_ADS_V0001.NC";
            String RDCFileName = "/mnt/fengyun_diqiu/tctbdata/tctbproduct/FY4A/AGRI/L3/DISK/HHMM/RDC---/NOM/" + year + "/" + yearMon + "/FY4A-_AGRI--_N_REGC_1047E_L3_RDC---_MULT_NOM_" + time + "0000_" + time + "1459_4000M_HHMM_ADS_V0001.NC";
            ;
            file = new File(MCSFileName);
            if (!file.exists()) {
                algorithmParams.put("parameter01", null);
                return algorithmParams;
            }
            file = new File(DCCFileName);
            if (!file.exists()) {
                algorithmParams.put("parameter01", null);
                return algorithmParams;
            }
            file = new File(RDCFileName);
            if (!file.exists()) {
                algorithmParams.put("parameter01", null);
                return algorithmParams;
            }
            String[] adsFile = {MCSFileName, DCCFileName, RDCFileName};
            params.put("primaryFile", primaryFile);
            params.put("adsFile", adsFile);
            params.put("productID", productID);
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        }
        //FY4A真彩图
        else if ("FY4AZCT".equals(adsType)) {
            String[] fileName = primaryFile.split("_");
            // /GHI/L1/20220618/FY4B-_GHI---_N_REGX_1330E_L1-_GEO-_MULT_NOM_20220618020900_20220618020959_2000M_V0001.HDF
            //                    0    1     2  3     4    5   6    7    8         9             10         11    12
            File file = new File(primaryFile);
            String FY4A_Path_FDI = primaryFile;
            String FY4A_Path_GEO = FY4A_Path_FDI.replace("FDI-", "GEO-").replace("1000M", "4000M");
//            String requestTif = "/mnt/fengyun_diqiu/data/FY4BDATA/FY4BTC/"+file.getName().replace(".HDF","")+".tif";
            String requestPath = taskPathParam.getParameter02() + File.separator + fileName[9].substring(0, 4) + File.separator + fileName[9].substring(0, 8);
            File requestFile = new File(requestPath);
            if (!requestFile.exists()) {
                requestFile.mkdirs();
            }
            String requestTif = taskPathParam.getParameter02() + File.separator + fileName[9].substring(0, 4) + File.separator + fileName[9].substring(0, 8) + File.separator + file.getName().replace(".HDF", "") + ".tif";
            algorithmParams.put("parameter00", taskPathParam.getParameter01());
            algorithmParams.put("parameter01", FY4A_Path_FDI);
            algorithmParams.put("parameter02", FY4A_Path_GEO);
            algorithmParams.put("parameter03", requestTif);
        } else if ("SCBNOM".equals(adsType)) {
            String[] fileName = primaryFile.split("_");
            //FY4A-_AGRI--_N_DISK_1047E_L3_ATI---_MULT_NOM_20220101000000_20220101235959_4000M_POAD_ADS_V0001.NC
            // 0     1     2   3    4    5  6      7    8       9               10          11  12
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
            String productType = taskPathParam.getParameter01();
            String endTime = "";
            String staTime = "";
            String day = fileName[9].substring(6, 8);
            if ("HSJ".equals(productType)) {
                Date endDate = sdf.parse(fileName[9]);
                Calendar cal = Calendar.getInstance();
                cal.setTime(endDate);
                cal.add(Calendar.HOUR_OF_DAY, -24);
                endTime = sdf.format(cal.getTime());
                switch (day) {
                    case "01":
                        staTime = endTime.substring(0, 6) + "26000000";
                        break;
                    case "06":
                        staTime = endTime.substring(0, 6) + "01000000";
                        break;
                    case "11":
                        staTime = endTime.substring(0, 6) + "10000000";
                        break;
                    case "16":
                        staTime = endTime.substring(0, 6) + "15000000";
                        break;
                    case "21":
                        staTime = endTime.substring(0, 6) + "20000000";
                        break;
                    case "26":
                        staTime = endTime.substring(0, 6) + "25000000";
                        break;
                }
            }
            if ("XSJ".equals(productType)) {
                Date endDate = sdf.parse(fileName[9]);
                Calendar cal = Calendar.getInstance();
                cal.setTime(endDate);
                cal.add(Calendar.HOUR_OF_DAY, -24);
                endTime = sdf.format(cal.getTime());
                switch (day) {
                    case "01":
                        staTime = endTime.substring(0, 6) + "20000000";
                        break;
                    case "11":
                        staTime = endTime.substring(0, 6) + "01000000";
                        break;
                    case "21":
                        staTime = endTime.substring(0, 6) + "10000000";
                        break;
                }
            }
            if ("YSJ".equals(productType)) {
                Date endDate = sdf.parse(fileName[9]);
                Calendar cal = Calendar.getInstance();
                cal.setTime(endDate);
                cal.add(Calendar.HOUR_OF_DAY, -24);
                endTime = sdf.format(cal.getTime());
                switch (day) {
                    case "01":
                        staTime = endTime.substring(0, 6) + "01000000";
                        break;
                }

            }
            if ("ZSJ".equals(productType)) {
                Date endDate = sdf.parse(fileName[9]);
                Calendar cal = Calendar.getInstance();
                cal.setTime(endDate);
                cal.add(Calendar.HOUR_OF_DAY, -24);
                endTime = sdf.format(cal.getTime());
                if (1 == DateUtil.dayOfWeek(cal.getTime())) {
                    cal.add(Calendar.HOUR_OF_DAY, -24 * 6);
                    staTime = sdf.format(cal.getTime());
                }
            }
            if ("".equals(staTime)) {
                algorithmParams.put("parameter01", null);
                return algorithmParams;
            }
            algorithmParams.put("parameter00", taskPathParam.getProductType());
            algorithmParams.put("parameter01", productType);
            algorithmParams.put("parameter02", staTime);
            algorithmParams.put("parameter03", endTime);
            algorithmParams.put("parameter04", taskPathParam.getParameter02());
        }
        return algorithmParams;
    }

    private String checkVal(String value) {
        if (!StringUtils.isEmpty(value)) {
            return value;
        }
        return "";
    }

    //如果是开始时间
    private static List<String[]> getFilesByTime(String filePath, String startTime, String endTime, String matche) {

        List<String[]> filePaths = new ArrayList<String[]>();
        List<String[]> truefilePaths = new ArrayList<String[]>();
        if (startTime.substring(0, 8).equals(endTime.substring(0, 8))) {
            //同一个文件夹的处理
            ///mnt/FY4DATA/AGRI/L1/FDI/DISK\\2021\\20210909
            String startFilePath = filePath + File.separator + startTime.substring(0, 4) + File.separator + startTime.substring(0, 8);
            filePaths.addAll(getFiles(startFilePath, matche));
        } else {
            String startFilePath = filePath + File.separator + startTime.substring(0, 4) + File.separator + startTime.substring(0, 8);
            String endFilePath = filePath + File.separator + endTime.substring(0, 4) + File.separator + endTime.substring(0, 8);
            filePaths.addAll(getFiles(startFilePath, matche));
            filePaths.addAll(getFiles(endFilePath, matche));
        }
        //比较时间是否在访问内
        for (String[] time : filePaths) {
            if (Long.valueOf(time[0]) >= Long.valueOf(startTime) && Long.valueOf(time[0]) < Long.valueOf(endTime)) {
                // filePaths.remove(time);
                truefilePaths.add(time);
            }
        }
        return truefilePaths;

    }

    //返回 时次  文件名 数组
    private static List<String[]> getFiles(String startFilePath, String matche) {
        List<String[]> filePaths = new ArrayList<String[]>();
        File startFileDir = new File(startFilePath);
        File[] startFiles = startFileDir.listFiles();
        if (startFiles == null) return filePaths;
        for (File file : startFiles) {
            //先匹配到文件
            String fn = FileUtil.getFileName(file.getAbsolutePath());
            //if(fn.matches(".*FDI.*4000M_V0001.HDF$")) { --matche
            if (fn.matches(matche)) {
                //匹配到文件
                String[] nameTime = new String[2];
                Pattern p = Pattern.compile("(\\d{4})(\\d{1,2})(\\d{1,2})(\\d{1,2})(\\d{1,2})(\\d{1,2})");
                Matcher m = p.matcher(fn);
                String time = "";
                while (m.find()) {
                    time = m.group();
                    break;
                }
                nameTime[0] = time;
                nameTime[1] = fn;
                filePaths.add(nameTime);
            }
        }
        return filePaths;
    }

    private void getclp(Map<String, Object> callParamterMap, String parameter, String time) {
        // //时间格式为 20190304230000
        String clp = (String) callParamterMap.get(parameter);
        //获取年月日

        String year = time.substring(0, 4);
        String moth = time.substring(0, 8);
        //获得L2级路径
        String l2FilePath = clp + "/" + year + "/" + moth;
        String filepath = "";
        File f = new File(l2FilePath);
        File[] fs = f.listFiles();
        for (File ff : fs) {
            String fn = FileUtil.getFileName(ff.getAbsolutePath());
            if (fn.contains(time) && fn.endsWith("4000M_V0001.NC")) {

                filepath = clp + "\\" + year + "\\" + moth + "\\" + fn;

                callParamterMap.put(parameter, filepath.replace("\\", "/"));
                break;
            }
        }

    }

    //检验源文件规则解析
    private String validationRule(String validationFile, String fileDate, String validationFile1) {
        StringBuilder filePathSb = new StringBuilder();
        if (StringUtils.isBlank(validationFile)) {
            return filePathSb.toString();
        }
        RuleVO ruleVO = JSON.parseObject(validationFile, RuleVO.class);
        if (NULL.equals(ruleVO.getMatchRule()) || NULL.equals(ruleVO.getLevel())) {
            return filePathSb.toString();
        }
        Map<String, String> timeRangeParam = parseTimeRange(fileDate, ruleVO.getTimeRange());
        String mathexp = ruleVO.getMatchRule();
        String satellite = ruleVO.getSatellite();
        String startTime = timeRangeParam.get("startTime");
        String endTime = timeRangeParam.get("endTime");
        List<DbDmsScanningValidationDTO> ruleFileList = dbDmsScanningValidationService
                .findBySatelliteAndDataLevelAndProductIdentifyAndFileDateBetween(satellite, ruleVO.getLevel(), mathexp, startTime, endTime);
        if (ruleFileList.isEmpty()) {
            logger.info("未查询到任何质检源数据文件");
            return null;
        }
        for (DbDmsScanningValidationDTO fileDTO : ruleFileList) {
            String currentFilePath = validationFile1 + File.separator + fileDTO.getFilePath();
            File file = new File(currentFilePath);
            if (!file.exists()) {
                logger.info("{}在磁盘上不存在", fileDTO.getFileName());
                return null;
            }
            filePathSb.append(",").append(currentFilePath);
        }

        return filePathSb.substring(1);
    }

    /**
     * @param inputParams 输入参数
     * @param ruleParams  规则参数
     * @param taskDTO     任务信息对象
     * @param data        处理的数据对象，自己定义
     */
    @Override
    public void parseRuleAndFindData(Map<String, Object> inputParams, Map<String, Object> ruleParams,
                                     HtScheduleJobDTO taskDTO, Object data) {
        HtScanningMetadataDTO metadataDTO = (HtScanningMetadataDTO) data;
        List<HtScanningMetadataDTO> dataList = new ArrayList<>();
        dataList.add(metadataDTO);
        AlgorithmTaskRuleParam taskRuleParam = JSON.parseObject(JSON.toJSONString(ruleParams), AlgorithmTaskRuleParam.class);
        AlgorithmTaskPathParam taskPathParam = JSON.parseObject(JSON.toJSONString(inputParams), AlgorithmTaskPathParam.class);
        assemble(taskRuleParam, taskPathParam, dataList, taskDTO);
    }

    private void assemble(AlgorithmTaskRuleParam taskRuleParam, AlgorithmTaskPathParam taskPathParam,
                          List<HtScanningMetadataDTO> dataList, HtScheduleJobDTO taskDTO) {
        assemble(taskRuleParam, taskPathParam, null, dataList, taskDTO);
    }

    /**
     * 校验输入规则的文件是否写入路径
     *
     * @param ruleParam
     * @param pathParam
     * @return
     */
    private boolean rulePathExist(AlgorithmTaskRuleParam ruleParam, AlgorithmTaskPathParam pathParam) {
        if (StringUtils.isBlank(ruleParam.getPrimaryFile())) {
            logger.info("主文件规则为空");
            return false;
        }
        /*if (StringUtils.isNotBlank(ruleParam.getGeoFile())) {
            RuleVO geoRuleVO = JSON.parseObject(ruleParam.getGeoFile(), RuleVO.class);
            if (!NULL.equals(geoRuleVO.getMatchRule()) && StringUtils.isBlank(pathParam.getGeoFile())) {
                logger.info("geo文件输入路径为空");
                return false;
            }
        }
        if (StringUtils.isNotBlank(ruleParam.getL2File())) {
            RuleVO l2RuleVO = JSON.parseObject(ruleParam.getL2File(), RuleVO.class);
            if (!NULL.equals(l2RuleVO.getMatchRule()) && StringUtils.isBlank(pathParam.getL2File())) {
                logger.info("L2文件输入路径为空");
                return false;
            }
        }
        if (StringUtils.isNotBlank(ruleParam.getNwpFile())) {
            RuleVO nwpRuleVO = JSON.parseObject(ruleParam.getNwpFile(), RuleVO.class);
            if (!NULL.equals(nwpRuleVO.getMatchRule()) && StringUtils.isBlank(pathParam.getNwpFile())) {
                logger.info("辅助（nwp）文件输入路径为空");
                return false;
            }
        }*/
        return true;
    }

    protected List<HtScanningMetadataDTO> selectEcExecMainFileList(RuleVO primaryRuleVO, boolean preprocess,
                                                                   HtScheduleJobDTO taskDTO) {
        //获取主波段或传感器参数（）
        if (StringUtils.isBlank(primaryRuleVO.getMatchRule()) || NULL.equals(primaryRuleVO.getMatchRule())) {
            new ArrayList<>();
        }
        String mainMathexp = primaryRuleVO.getMatchRule().split(",|\\|")[0];
        String productIdentify = primaryRuleVO.getProductIdentify();
        String taskType = taskDTO.getTaskType();
        LocalDateTime now = LocalDateTime.now();
        //从算法执行时间往前推一百天
        Date redoStartTime = taskDTO.getRedoStartTime();
        Calendar cal = Calendar.getInstance();
        cal.setTime(redoStartTime);
//        String startTime = TIME_FORMAT.format(cal.toInstant().atZone(ZoneId.systemDefault()));
        String startTime = TIME_FORMAT.format(now.plusDays(-1L * nearDay));
        String endTime = TIME_FORMAT.format(now);
        Pattern p = Pattern.compile(mainMathexp);
        if ("redo_singleTask".equals(taskType)) {
//            Date redoStartTime = taskDTO.getRedoStartTime();
            Date redoEndTime = taskDTO.getRedoEndTime();

            Calendar cale = Calendar.getInstance();
            cale.setTime(redoEndTime);
//            startTime = TIME_FORMAT.format(redoStartTime.toInstant().atZone(ZoneId.systemDefault()));
            endTime = TIME_FORMAT.format(cale.toInstant().atZone(ZoneId.systemDefault()));
        }
        List<HtScanningMetadataDTO> metaDataList = null;
        List<HtScanningMetadataDTO> allMetaDataList = new ArrayList<>();
        /*
            预处理：根据传入的传感器，时间范围，数据等级查询。
            专业处理：根据传入的通道，时间范围，文件类型（L2X、L2Y的文件类型为TIFF），数据等级查询。
         */
        /*if (preprocess) {
            allMetaDataList = htScanningMetadataService.listBySensorAndRangeTimeAndLevel(mainMathexp,startTime,endTime,primaryRuleVO.getLevel());
        } else {
            allMetaDataList = htScanningMetadataService.listByBandsAndDataLevelAndProductIidAndRangeTime(mainMathexp,primaryRuleVO.getLevel(),productIdentify,startTime,endTime);
        }*/

        metaDataList = htScanningMetadataService.findByMetadata(startTime, endTime, primaryRuleVO.getLevel(), primaryRuleVO.getSatellite(), primaryRuleVO.getProductIdentify());
        for (HtScanningMetadataDTO dto : metaDataList) {
            Matcher matcher = p.matcher(dto.getFileName());
            if (matcher.matches()) {
                allMetaDataList.add(dto);
            }
        }
        List<HtScanningMetadataDTO> ecMetaDataList = new ArrayList<>();
        for (HtScanningMetadataDTO htScanningMetadataDTO : allMetaDataList) {

            String fy4aFileName = htScanningMetadataDTO.getFileName();
            logger.info(htScanningMetadataDTO.getFileName());
            String[] fileName = htScanningMetadataDTO.getFileName().split("_");
            String yearMon = fileName[9].substring(0, 8);
            String time = fileName[9].substring(0, 10);
            DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMddHH");
            DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyyMMdd");
            LocalDateTime localDate = LocalDateTime.parse(time, dtf);
            File[] fs;
            Pattern pattern;
            String L1_time = fileName[9].substring(8, 12);
            if (L1_time.equals("0000") || L1_time.equals("0300") || L1_time.equals("0600") || L1_time.equals("0900") || L1_time.equals("1200") || L1_time.equals("1500") || L1_time.equals("1800") || L1_time.equals("2100")) {
                for (int i = 0; i <= 6; i++) {
                    HtScanningMetadataDTO dto = new HtScanningMetadataDTO();
                    dto.setFileDate(htScanningMetadataDTO.getFileDate());
                    dto.setLon(htScanningMetadataDTO.getLon());
                    dto.setLat(htScanningMetadataDTO.getLat());
                    dto.setTaskPlanId(htScanningMetadataDTO.getTaskPlanId());
                    dto.setSubPlanId(htScanningMetadataDTO.getSubPlanId());
                    dto.setViewNumber(htScanningMetadataDTO.getViewNumber());
                    dto.setFilePath(htScanningMetadataDTO.getFilePath());
                    int days = i / 2;
                    int type = i % 2;
                    String ECPath = "";
                    if (Integer.valueOf(L1_time.substring(0, 2)) >= 0 && Integer.valueOf(L1_time.substring(0, 2)) < 12) {
                        if (i == 0) {
                            continue;
                        }
                        LocalDate sld = LocalDate.parse(yearMon, dtf1).minusDays(days);
                        String sMinusDate = sld.format(dtf1);
                        //    0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
                        //days0 0 1 1 2 2 3 3 4 4 5  5   6  6  7  7
                        //type0 1 0 1 0 1 0 1 0 1 0  1   0  1  0  1
                        if (type == 1) {
                            ECPath = "/mnt/swapdata/Forecast/NAFP/ECMWF/HRES/" + File.separator + sMinusDate + File.separator + "00/gh/";
                        } else {
                            ECPath = "/mnt/swapdata/Forecast/NAFP/ECMWF/HRES/" + File.separator + sMinusDate + File.separator + "12/gh/";
                        }
                        logger.info("EC路径：" + ECPath);
                        File EC_file = new File(ECPath);        //获取其file对象
                        fs = EC_file.listFiles();
                        pattern = Pattern.compile("W_NAFP_C_ECMF_(\\d{14})_P_C1D(\\d{8})" + dtf.format(LocalDateTime.parse(dtf.format(localDate), dtf)).substring(4, 10) + "(\\d{2})1.gh.nc");
                        logger.info("正则:" + "W_NAFP_C_ECMF_(\\d{14})_P_C1D(\\d{8})" + dtf.format(LocalDateTime.parse(dtf.format(localDate), dtf)).substring(4, 10) + "(\\d{2})1.gh.nc");
                        if (EC_file.exists()) {
                            for (File fi : fs) {
                                Matcher m = pattern.matcher(fi.getName());
                                while (m.find()) {
                                    logger.info("EC名称：" + fy4aFileName + "#" + m.group());
                                    dto.setFileName(fy4aFileName + "#" + m.group());
                                    dto.setViewMode(ECPath + File.separator + m.group());
                                    ecMetaDataList.add(dto);
                                }
                            }
                        }
                    } else {
                        if (i > 5) {
                            continue;
                        }
                        LocalDate sld = LocalDate.parse(yearMon, dtf1).minusDays(days);
                        String sMinusDate = sld.format(dtf1);
                        if (type == 1) {
                            ECPath = "/mnt/swapdata/Forecast/NAFP/ECMWF/HRES/" + File.separator + sMinusDate + File.separator + "00/gh/";
                        } else {
                            ECPath = "/mnt/swapdata/Forecast/NAFP/ECMWF/HRES/" + File.separator + sMinusDate + File.separator + "12/gh/";
                        }
                        logger.info("EC路径：" + ECPath);
                        File EC_file = new File(ECPath);        //获取其file对象
                        fs = EC_file.listFiles();
                        pattern = Pattern.compile("W_NAFP_C_ECMF_(\\d{14})_P_C1D(\\d{8})" + dtf.format(LocalDateTime.parse(dtf.format(localDate), dtf)).substring(4, 10) + "(\\d{2})1.gh.nc");
                        logger.info("正则:" + "W_NAFP_C_ECMF_(\\d{14})_P_C1D(\\d{8})" + dtf.format(LocalDateTime.parse(dtf.format(localDate), dtf)).substring(4, 10) + "(\\d{2})1.gh.nc");
                        if (EC_file.exists()) {
                            for (File fi : fs) {
                                Matcher m = pattern.matcher(fi.getName());
                                while (m.find()) {
                                    logger.info("EC名称：" + fy4aFileName + "#" + m.group());
                                    dto.setFileName(fy4aFileName + "#" + m.group());
                                    dto.setViewMode(ECPath + File.separator + m.group());
                                    ecMetaDataList.add(dto);
                                }
                            }
                        }
                    }
                }
            }

        }
        List<DbDmsSchedulerTaskFileRecordDTO> existRecordDataList = dbDmsSchedulerTaskFileRecordService.findByTaskId(taskDTO.getId());
        List<HtScanningMetadataDTO> execMetadataList = null;
        //过滤需要执行的主文件，如果记录表中为空则查询出的时间范围内所有文件都执行，如果不为空，则筛选掉已经执行过的。
        if (existRecordDataList.isEmpty()) {
            execMetadataList = ecMetaDataList;
        } else {
            Map<String, DbDmsSchedulerTaskFileRecordDTO> hash = existRecordDataList.stream().
                    collect(Collectors.toMap(DbDmsSchedulerTaskFileRecordDTO::getFileName, dto -> dto, (v1, v2) -> v2));
            execMetadataList = ecMetaDataList.stream().filter(dto -> !hash.containsKey(dto.getFileName())).collect(Collectors.toList());
        }
        return execMetadataList;
    }

    protected List<HtScanningMetadataDTO> selectExecMainFileList(RuleVO primaryRuleVO, boolean preprocess,
                                                                 HtScheduleJobDTO taskDTO) {
        //获取文件匹配规则
        if (StringUtils.isBlank(primaryRuleVO.getMatchRule()) || NULL.equals(primaryRuleVO.getMatchRule())) {
            new ArrayList<>();
        }
        String mainMathexp = primaryRuleVO.getMatchRule().split(",|\\|")[0];
        //产品标识
        String productIdentify = primaryRuleVO.getProductIdentify();
        //任务类型
        String taskType = taskDTO.getTaskType();
        LocalDateTime now = LocalDateTime.now();
        //从算法执行时间往前推一百天
        java.util.Date redoStartTime = taskDTO.getRedoStartTime();
        Calendar cal = Calendar.getInstance();
        cal.setTime(redoStartTime);
        String startTime = TIME_FORMAT.format(cal.toInstant().atZone(ZoneId.systemDefault()));
//        String startTime = TIME_FORMAT.format(now.plusDays(-1L * nearDay));
        String endTime = TIME_FORMAT.format(now);
        Pattern p = Pattern.compile(mainMathexp);
        if ("redo_singleTask".equals(taskType)) {
//            Date redoStartTime = taskDTO.getRedoStartTime();
            java.util.Date redoEndTime = taskDTO.getRedoEndTime();

            Calendar cale = Calendar.getInstance();
            cale.setTime(redoEndTime);
//            startTime = TIME_FORMAT.format(redoStartTime.toInstant().atZone(ZoneId.systemDefault()));
            endTime = TIME_FORMAT.format(cale.toInstant().atZone(ZoneId.systemDefault()));
        }
        List<HtScanningMetadataDTO> metaDataList = null;
        List<HtScanningMetadataDTO> allMetaDataList = new ArrayList<>();
        /*
            预处理：根据传入的传感器，时间范围，数据等级查询。
            专业处理：根据传入的通道，时间范围，文件类型（L2X、L2Y的文件类型为TIFF），数据等级查询。
         */
        /*if (preprocess) {
            allMetaDataList = htScanningMetadataService.listBySensorAndRangeTimeAndLevel(mainMathexp,startTime,endTime,primaryRuleVO.getLevel());
        } else {
            allMetaDataList = htScanningMetadataService.listByBandsAndDataLevelAndProductIidAndRangeTime(mainMathexp,primaryRuleVO.getLevel(),productIdentify,startTime,endTime);
        }*/

//        metaDataList = htScanningMetadataService.findByMetadata(startTime, endTime, primaryRuleVO.getLevel(), primaryRuleVO.getSatellite(), primaryRuleVO.getProductIdentify(), primaryRuleVO.getRegion());
        for (HtScanningMetadataDTO dto : metaDataList) {
            Matcher matcher = p.matcher(dto.getFileName());
            if (matcher.matches()) {
                allMetaDataList.add(dto);
            }
        }
        List<String> allNameList = allMetaDataList.stream().map(x -> x.getFileName()).collect(Collectors.toList());

        List<DbDmsSchedulerTaskFileRecordDTO> existRecordDataList = dbDmsSchedulerTaskFileRecordService.findByTaskIdAndFileNameIn(taskDTO.getId(), allNameList);
        List<HtScanningMetadataDTO> execMetadataList = null;
        //过滤需要执行的主文件，如果记录表中为空则查询出的时间范围内所有文件都执行，如果不为空，则筛选掉已经执行过的。
        if (existRecordDataList.isEmpty()) {
            execMetadataList = allMetaDataList;
        } else {
            Map<String, DbDmsSchedulerTaskFileRecordDTO> hash = existRecordDataList.stream().
                    collect(Collectors.toMap(DbDmsSchedulerTaskFileRecordDTO::getFileName, dto -> dto, (v1, v2) -> v2));
            execMetadataList = allMetaDataList.stream().filter(dto -> !hash.containsKey(dto.getFileName())).collect(Collectors.toList());
        }
        return execMetadataList;
    }

    protected List<HtScanningMetadataDTO> findRedoMetadataList(String taskId) {
        List<DbDmsSchedulerTaskFileRecordDTO> redoTaskRecordList = dbDmsSchedulerTaskFileRecordService.findRedoTasks(taskId);
        List<String> fileNameList = redoTaskRecordList.stream()
                .map(DbDmsSchedulerTaskFileRecordDTO::getFileName).collect(Collectors.toList());
        return htScanningMetadataService.findByFileNameList(fileNameList);
    }

    private String primaryRule(RuleVO primaryFileRule, boolean preprocess, HtScanningMetadataDTO mainFileDTO,
                               HtPathConfigurationDTO pathDTO, String matchRule) {
        //主文件规则时间范围
        String mainFileDate = mainFileDTO.getFileDate();
        Map<String, String> timeRangeParam = parseTimeRange(mainFileDate, primaryFileRule.getTimeRange());
        //查找满足要求的所有文件列表
        String[] mathexpArr = matchRule.split("\\|");
        String leftTime = timeRangeParam.get("startTime");
        String rightTime = timeRangeParam.get("endTime");
        //如果没有输入时间参数，则默认考虑正负3分钟查找文件，经纬度满足正负0.5°
        if (leftTime.equals(rightTime)) {
            return findPrimaryFileList(mainFileDTO, primaryFileRule.getLevel(), pathDTO, Arrays.asList(mathexpArr), preprocess);
        } else {
            //1、根据主通道找到输入的时间范围内的所有主通道文件。2、根据不同时次的主通道正负3分钟找到同一谱段的其他通道文件，拼接
            List<HtScanningMetadataDTO> mainBandsFileList = htScanningMetadataService
                    .listByBandsAndDataLevelAndRangeTime(mainFileDTO.getBands(), primaryFileRule.getLevel(), leftTime, rightTime);
            if (mainBandsFileList.isEmpty()) {
                logger.info("未查询到多个谱段的主通道文件时");
                return null;
            }
            StringBuilder primaryFilePath = new StringBuilder();
            for (HtScanningMetadataDTO dto : mainBandsFileList) {
                String path = findPrimaryFileList(dto, primaryFileRule.getLevel(), pathDTO, Arrays.asList(mathexpArr), preprocess);
                if (path == null) {
                    return null;
                }
                primaryFilePath.append(";").append(path);
            }
            return primaryFilePath.substring(1);
        }
    }

    /**
     * 获取primaryFile文件列表信息
     *
     * @param mainFileDTO
     * @param level
     * @param bandsList
     * @return
     */
    private String findPrimaryFileList(HtScanningMetadataDTO mainFileDTO, String level, HtPathConfigurationDTO pathDTO,
                                       List<String> bandsList, boolean preProcess) {
        List<HtScanningMetadataDTO> resultList = null;
        //标准化处理
        if (preProcess) {
            resultList = new ArrayList<>();
            resultList.add(mainFileDTO);
        } else {
            String mainFileDate = mainFileDTO.getFileDate();
            String leftTime = TIME_FORMAT.format(LocalDateTime.parse(mainFileDate, TIME_FORMAT).plusMinutes(-1 * DIFF_TIME_MINUTE));
            String rightTime = TIME_FORMAT.format(LocalDateTime.parse(mainFileDate, TIME_FORMAT).plusMinutes(DIFF_TIME_MINUTE));
            List<HtScanningMetadataDTO> dataList = htScanningMetadataService
                    .listByBandsAndDataLevelRangeTime(bandsList, level, leftTime, rightTime);
            if (dataList.isEmpty()) {
                return null;
            }
            double lon = Double.parseDouble(mainFileDTO.getLon().substring(1));
            double lat = Double.parseDouble(mainFileDTO.getLat().substring(1));
            resultList = dataList.stream().filter(dto -> {
                double dLon = Double.parseDouble(dto.getLon().substring(1));
                double dLat = Double.parseDouble(dto.getLat().substring(1));
                return dLon >= lon - 0.5 && dLon <= lon + 0.5 && dLat >= lat - 0.5 && dLat <= lat + 0.5;
            }).collect(Collectors.toList());
            //校验查询出的数据是否和输入通道数量匹配
            Map<String, List<HtScanningMetadataDTO>> hash = resultList.stream().collect(Collectors.groupingBy(HtScanningMetadataDTO::getBands));
            if (hash.size() != bandsList.size()) {
                logger.info("查询出的通道数量与输入数量不匹配");
                return null;
            }
            List<HtScanningMetadataDTO> tempList = new ArrayList<>();
            long mainFileMilli = LocalDateTime.parse(mainFileDate, TIME_FORMAT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
            hash.values().forEach(list -> {
                HtScanningMetadataDTO resultDTO = list.stream().min((a, b) -> {
                    long aMilli = LocalDateTime.parse(a.getFileDate(), TIME_FORMAT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
                    long bMilli = LocalDateTime.parse(b.getFileDate(), TIME_FORMAT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
                    return Math.abs(aMilli - mainFileMilli) > Math.abs(bMilli - mainFileMilli) ? 1 : -1;
                }).get();
                tempList.add(resultDTO);
            });
            resultList = tempList;
        }
        //判断磁盘上是否存在文件
        StringBuilder sb = new StringBuilder();
        for (HtScanningMetadataDTO dto : resultList) {
            String currentFilePath = pathDTO.getClientPath() + File.separator + dto.getFilePath();
            File file = new File(currentFilePath);
            if (!file.exists()) {
                return null;
            }
            sb.append(",").append(currentFilePath);
        }
        return sb.substring(1);
    }

    private Map<String, String> geoRule(String geoRule, boolean preProcess, HtScanningMetadataDTO mainFileDTO, String geoPathPrefix) {
        StringBuilder geoPathSb = new StringBuilder();
        StringBuilder rpbPathSb = new StringBuilder();
        Map<String, String> resultMap = new HashMap<>();
        resultMap.put("geo", "");
        resultMap.put("rpb", "");
        if (StringUtils.isBlank(geoRule)) {
            return resultMap;
        }
        RuleVO geoRuleVO = JSON.parseObject(geoRule, RuleVO.class);
        if (NULL.equals(geoRuleVO.getMatchRule()) || NULL.equals(geoRuleVO.getLevel())) {
            return resultMap;
        }
        Map<String, String> timeRangeParam = parseTimeRange(mainFileDTO.getFileDate(), geoRuleVO.getTimeRange());
        String[] mathexpArr = geoRuleVO.getMatchRule().split("\\|");
        List<HtScanningMetadataDTO> ruleFileList = null;
        //标准化处理根据传感器，时间范围，数据等级，查询
        String startTime = timeRangeParam.get("startTime");
        String endTime = timeRangeParam.get("endTime");
        if (preProcess) {
            ruleFileList = htScanningMetadataService.listBySensorAndRangeTimeAndLevelAndBand(mainFileDTO.getSensor(), startTime,
                    endTime, geoRuleVO.getLevel(), mainFileDTO.getBands());
            Set<String> mathexpHashSet = new HashSet<>(Arrays.asList(mathexpArr));
            ruleFileList = ruleFileList.stream().filter(item -> {
                String name = item.getFileName();
                String[] splitName = name.split("_");
                return mathexpHashSet.contains(splitName[splitName.length - 2]);
            }).collect(Collectors.toList());
            if (ruleFileList.size() != mathexpHashSet.size()) {
                logger.info("主文件{}扫描过程中，查询geo文件和rpb文件时输入参数和查询出的数量不一致", mainFileDTO.getFileName());
                return null;
            }
        } else {
            //TODO 专业处理时HTHTGEO扫描规则
//            ruleFileList = htScanningMetadataService.listByProductIidAndBandsAndDataLevelAndLonAndLatAndTimeRange(mathexpArr[0],mainFileDTO.getBands(),
//                    geoRuleVO.getLevel(),mainFileDTO.getLon(),mainFileDTO.getLat(),startTime,endTime);
        }
        if (ruleFileList.isEmpty()) {
            logger.info("未查询到任何geo或rgb文件");
            return null;
        }
        for (HtScanningMetadataDTO fileDTO : ruleFileList) {
            String currentFilePath = geoPathPrefix + File.separator + fileDTO.getFilePath();
            File file = new File(currentFilePath);
            if (!file.exists()) {
                logger.info("{}在磁盘上不存在", fileDTO.getFileName());
                return null;
            }
            if ("HDF".equals(fileDTO.getFileType())) {
                geoPathSb.append(",").append(currentFilePath);
            } else if ("RPB".equals(fileDTO.getFileType())) {
                rpbPathSb.append(",").append(currentFilePath);
            }
        }
        String geoPath = geoPathSb.toString();
        String rpbPath = rpbPathSb.toString();
        if (StringUtils.isNotBlank(geoPath)) {
            resultMap.put("geo", geoPath.substring(1));
        }
        if (StringUtils.isNotBlank(rpbPath)) {
            resultMap.put("rpb", rpbPath.substring(1));
        }
        return resultMap;
    }

    private String l2Rule(String rule, HtScanningMetadataDTO mainFileDTO, String l2PathPrefix) {
        StringBuilder filePathSb = new StringBuilder();
        if (StringUtils.isBlank(rule)) {
            return filePathSb.toString();
        }
        RuleVO l2RuleVO = JSON.parseObject(rule, RuleVO.class);
        if (NULL.equals(l2RuleVO.getMatchRule()) || NULL.equals(l2RuleVO.getLevel())) {
            return filePathSb.toString();
        }
        Map<String, String> timeRangeParam = parseTimeRange(mainFileDTO.getFileDate(), l2RuleVO.getTimeRange());
        String[] mathexpArr = l2RuleVO.getMatchRule().split("\\|");
        List<HtScanningMetadataDTO> ruleFileList;
        String startTime = timeRangeParam.get("startTime");
        String endTime = timeRangeParam.get("endTime");
        boolean isSingleTimes = false;
        if (startTime.equals(endTime)) {
            isSingleTimes = true;
            startTime = TIME_FORMAT.format(LocalDateTime.parse(mainFileDTO.getFileDate(), TIME_FORMAT).plusMinutes(-1 * DIFF_TIME_MINUTE));
            endTime = TIME_FORMAT.format(LocalDateTime.parse(mainFileDTO.getFileDate(), TIME_FORMAT).plusMinutes(DIFF_TIME_MINUTE));
            List<HtScanningMetadataDTO> dataList = htScanningMetadataService
                    .listByProductIidListAndTimeRangeAndLevel(Arrays.asList(mathexpArr), startTime, endTime, l2RuleVO.getLevel());
            double lon = Double.parseDouble(mainFileDTO.getLon().substring(1));
            double lat = Double.parseDouble(mainFileDTO.getLat().substring(1));
            ruleFileList = dataList.stream().filter(dto -> {
                double dLon = Double.parseDouble(dto.getLon().substring(1));
                double dLat = Double.parseDouble(dto.getLat().substring(1));
                return dLon >= lon - 0.5 && dLon <= lon + 0.5 && dLat >= lat - 0.5 && dLat <= lat + 0.5;
            }).collect(Collectors.toList());
        } else {
            //TODO L2多时次文件查询规则，暂时用不到
            logger.info("多时次查询");
            ruleFileList = new ArrayList<>();
        }
        Map<String, List<HtScanningMetadataDTO>> filterMap = ruleFileList.stream()
                .collect(Collectors.groupingBy(HtScanningMetadataDTO::getProductIid));
        if (filterMap.size() != mathexpArr.length) {
            logger.info("与主文件{}要求的L2级文件数量与L2级规则产品标识数量不一致", mainFileDTO.getFileName());
            return null;
        }
        if (isSingleTimes) {
            List<HtScanningMetadataDTO> tempList = new ArrayList<>();
            long mainFileMilli = LocalDateTime.parse(mainFileDTO.getFileDate(), TIME_FORMAT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
            filterMap.values().forEach(list -> {
                HtScanningMetadataDTO resultDTO = list.stream().min((a, b) -> {
                    long aMilli = LocalDateTime.parse(a.getFileDate(), TIME_FORMAT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
                    long bMilli = LocalDateTime.parse(b.getFileDate(), TIME_FORMAT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
                    return Math.abs(aMilli - mainFileMilli) > Math.abs(bMilli - mainFileMilli) ? 1 : -1;
                }).get();
                tempList.add(resultDTO);
            });
            ruleFileList = tempList;
        }
        for (HtScanningMetadataDTO fileDTO : ruleFileList) {
            String currentPath = l2PathPrefix + File.separator + fileDTO.getFilePath();
            File file = new File(currentPath);
            if (!file.exists()) {
                return null;
            }
            filePathSb.append(",").append(currentPath);
        }
        return filePathSb.substring(1);
    }

    private String nwpRule(String nwpFile, String mainFileDate, String npwPathPrefix) {
        StringBuilder filePathSb = new StringBuilder();
        if (StringUtils.isBlank(nwpFile)) {
            return filePathSb.toString();
        }
        RuleVO nwpRuleVO = JSON.parseObject(nwpFile, RuleVO.class);
        if (NULL.equals(nwpRuleVO.getMatchRule()) || NULL.equals(nwpRuleVO.getLevel())) {
            return filePathSb.toString();
        }
        //将主文件时间转为世界时来匹配数值预报数据
        mainFileDate = TIME_FORMAT.format(LocalDateTime.parse(mainFileDate, TIME_FORMAT).plusHours(-8L));
        //查询48小时内在数据库种条件要素的文件是否存在，并且数量至少为3个。
        Long earlyHour = (-1) * 48L;
        String earlyTime = TIME_FORMAT.format(LocalDateTime.parse(mainFileDate, TIME_FORMAT).plusHours(earlyHour));
        String[] mathexpArr = nwpRuleVO.getMatchRule().split("\\|");
        List<DbDmsScanningMetadataAuxInfoDTO> earlyAllData = dbDmsScanningMetadataAuxInfoService.
                listByFileWantListAndRangeTimeOrder(Arrays.asList(mathexpArr), earlyTime, mainFileDate);
        Map<String, Long> countAllNwpMap = earlyAllData.stream()
                .collect(Collectors.groupingBy(DbDmsScanningMetadataAuxInfoDTO::getFileWant, Collectors.counting()));
        if (mathexpArr.length != countAllNwpMap.size()) {
            logger.info("48小时内满足的要素种类数量不正确");
            return null;
        }
        for (Map.Entry<String, Long> entry : countAllNwpMap.entrySet()) {
            if (entry.getValue() < 3) {
                logger.info("{}--->要素的数量在48小时的范围内小于3", entry.getKey());
            }
        }
        //过滤筛筛选出符合规则要求的时次的要素文件  每种要素3个数据信息
        Map<String, String> timeRangeParam = parseTimeRange(mainFileDate, nwpRuleVO.getTimeRange());
        LocalDateTime nwpStartTime = LocalDateTime.parse(timeRangeParam.get("startTime"), TIME_FORMAT);
        LocalDateTime nwpEndTime = LocalDateTime.parse(timeRangeParam.get("endTime"), TIME_FORMAT);
        //key:要素 value:[nwp数据（时间+时次会重复）]
        Map<String, List<DbDmsScanningMetadataAuxInfoDTO>> filterMap = earlyAllData.stream().filter(dto -> {
            LocalDateTime dtoLocalDateTime = LocalDateTime.parse(dto.getFileDate(), TIME_FORMAT).plusHours(dto.getFileTimeSecond());
            return !nwpStartTime.isAfter(dtoLocalDateTime) && !nwpEndTime.isBefore(dtoLocalDateTime);
        }).collect(Collectors.groupingBy(DbDmsScanningMetadataAuxInfoDTO::getFileWant));
        for (Map.Entry<String, List<DbDmsScanningMetadataAuxInfoDTO>> entry : filterMap.entrySet()) {
            List<DbDmsScanningMetadataAuxInfoDTO> wantList = entry.getValue();
            List<DbDmsScanningMetadataAuxInfoDTO> nwpInfoList = new ArrayList<>();
            Map<String, DbDmsScanningMetadataAuxInfoDTO> hash = new HashMap<>();
            for (DbDmsScanningMetadataAuxInfoDTO nwpDTO : wantList) {
                String formatDate = TIME_FORMAT.format(LocalDateTime.parse(nwpDTO.getFileDate(), TIME_FORMAT).plusHours(nwpDTO.getFileTimeSecond()));
                if (!hash.containsKey(formatDate)) {
                    hash.put(formatDate, nwpDTO);
                    nwpInfoList.add(nwpDTO);
                }
            }
            if (nwpInfoList.size() < 3) {
                logger.info("{}要素在规则的时间范围内个数小于3", entry.getKey());
                return null;
            }
            //查找最接近的三个数量文件
            List<Long> nearPrimaryFileTime = findNearDateNwpFile(nwpInfoList, mainFileDate);
            //判断磁盘上是否存在
            StringBuilder sb = new StringBuilder();
            for (Long keyMilli : nearPrimaryFileTime) {
                String keyTime = TIME_FORMAT.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(keyMilli), ZoneId.systemDefault()));
                DbDmsScanningMetadataAuxInfoDTO currentFileDTO = hash.get(keyTime);
                String currentPath = npwPathPrefix + File.separator + currentFileDTO.getFilePath();
                File file = new File(currentPath);
                if (!file.exists()) {
                    logger.info("{}--->nwp文件在磁盘上不存在", file.getName());
                    return null;
                }
                sb.append(",").append(currentPath);
            }
            filePathSb.append(";").append(sb.substring(1));
        }
        return filePathSb.substring(1);
    }

    private List<Long> findNearDateNwpFile(List<DbDmsScanningMetadataAuxInfoDTO> nwpInfoList, String mainFileDate) {
        long primaryFileMilli = LocalDateTime.parse(mainFileDate, TIME_FORMAT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
        List<Long> nearPrimaryFileTime = new ArrayList<>();
        for (int j = 0; j < nwpInfoList.size(); j++) {
            DbDmsScanningMetadataAuxInfoDTO metadataAuxInfoDTO = nwpInfoList.get(j);
            long currentFileMilli = LocalDateTime.parse(metadataAuxInfoDTO.getFileDate(), TIME_FORMAT)
                    .plusHours(metadataAuxInfoDTO.getFileTimeSecond())
                    .atZone(ZoneId.systemDefault())
                    .toInstant()
                    .toEpochMilli();
            if (j < 3) {
                nearPrimaryFileTime.add(currentFileMilli);
            } else {
                //主文件时次右边是从大到小遍历，所以直接替换，保持最右是最小最近的文件时间，最左边是最大的。
                if (currentFileMilli - primaryFileMilli >= 0) {
                    nearPrimaryFileTime.remove(0);
                    nearPrimaryFileTime.add(currentFileMilli);
                } else {
                    //左边进行比较
                    long dif = primaryFileMilli - currentFileMilli;
                    long max = nearPrimaryFileTime.stream().max((a, b) -> Math.abs(a - primaryFileMilli) > Math.abs(b - primaryFileMilli) ? 1 : -1).get();
                    if (dif < Math.abs(max - primaryFileMilli)) {
                        nearPrimaryFileTime.remove(max);
                        nearPrimaryFileTime.add(currentFileMilli);
                    } else {
                        break;
                    }
                }
            }
        }
        return nearPrimaryFileTime;
    }


    private Map<String, String> parseTimeRange(String mainFileDate, String timeRange) {
        Map<String, String> resultMap = new HashMap<>();
        resultMap.put("startTime", mainFileDate);
        resultMap.put("endTime", mainFileDate);
        if (timeRange.equals("NULL")) {
            return resultMap;
        }
        String[] timeSplit = timeRange.split(",");
        long startPlusMinute = -1 * Math.abs(Long.parseLong(timeSplit[0]));
        long endPlusMinute = Math.abs(Long.parseLong(timeSplit[1]));
        LocalDateTime mainFileLocalDateTime = LocalDateTime.parse(mainFileDate, TIME_FORMAT);
        String startTime = TIME_FORMAT.format(mainFileLocalDateTime.plusMinutes(startPlusMinute));
        String endTime = TIME_FORMAT.format(mainFileLocalDateTime.plusMinutes(endPlusMinute));
        resultMap.put("startTime", startTime);
        resultMap.put("endTime", endTime);
        return resultMap;
    }


}
